How do I setup and run email using JavaMail?

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());
}

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What is the directory structure for my Context?

*.html, *.jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the...

What is a Tomcat manager and how do I use it ?

In many production environments, it is very useful to have the capability to deploy a new web...

Where can I obtain more information on running apps under Tomcat ?

You can find a lot of resources @ http://tomcat.apache.org/tomcat-4.0-doc/index.html

I have a Professional Plan, why is JSP not enabled on my account?

Since not all of our clients that order Professional Plans require JSP support, we don't enable...

When I try to connect to the database I get the following error:

When I try to connect to the database I get the following error: javax.servlet.ServletException:...

Powered by WHMCompleteSolution