Knowledgebase

How do I setup and run email using JavaMail? Print

  • 24

If your code sends out an email, you need to be aware of a few issues.

In order for for us to prevent unauthorized use of our smtp servers, we limit access to our clients. Therefore, before sending out any email, you must authenticate yourself against our system.

Java Code looks as follows:

import java.util.*,
import javax.mail.*,
import javax.mail.internet.*,


Properties props = new Properties();

props.put("mail.smtp.host", "smtp.your_mail_server.com");
Session s = Session.getInstance(props,null);

MimeMessage message = new MimeMessage(s);

// ***** IMPORTANT *******
// THIS MUST BE A VALID EMAIL ON YOUR DOMAIN!!!!
String sFrom = "email@yourdomain.com";
// **************************
String sTo = "some@somedomain.com";
String sSubject = "test mail";
String sBody = "this is the test";


try {
InternetAddress from = new InternetAddress(sFrom);
message.setFrom(from);
InternetAddress to = new InternetAddress(sTo);
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject(sSubject);
message.setText(sBody);

Store store = s.getStore("pop3");
store.connect( "pop.you_mail_server.com", your_username, your_password );

Transport.send(message);
out.println("message sent");
} catch (Exception e) {
out.println(e.getMessage());
}


Was this answer helpful?

« Back

Powered by WHMCompleteSolution


malware removal and website security

© Tech Logic Solutions Inc. All Rights Reserved

Bradford - Newmarket - Barrie - Toronto - Halifax - Vancouver - Calgary - Edmonton - Regina - Winnipeg - Ottawa - Montreal - Canada - USA - UK