

Configuring SMTP serverWe configure the settings for SMTP server in the web deployment descriptor file ( web.xml) as follows: The users will finally receives a Result.jsp page which tells them whether the e-mail was sent or not. It reads message details (recipient, subject and content) from EmailForm.jsp page and tries to sending the e-mail by invoking the sendEmail() method of the EmailUtility class. creates a new session with an authenticatorĪuthenticator auth = new Authenticator() As we can see, the servlet, EmailSendingServlet - loads configuration for SMTP server upon initialization in its init() method, and handles user’s requests in the doPost() method. Properties properties = new Properties() String subject, String message) throws AddressException,

Public static void sendEmail(String host, String port,įinal String userName, final String password, String toAddress, * A utility class for sending e-mail messages Code Java E-mail utility classBased on the article Send e-mail in plain text using JavaMail we write a utility class called EmailUtility.java as follows: package how to build, deploy and run an application with a servlet container like Tomcat.Okay, let’s build the application now. NOTE: this tutorial is supposing you are already familiar with Java web application development, i.e. Send e-mail in plain text using JavaMail for how to write code to send a simple e-mail message.How to start e-mail programming in Java for how to download and use JavaMail.If you are new to JavaMail, the following articles would be helpful: The only external library required is JavaMail. The application can be deployed on any servlet container that supports Servlet 3.0 API such as Tomcat 7.0. The following diagram describes workflow of the application: Code in this tutorial is applied for Servlet 3.0, any version of JSP and JavaMail 1.4. This tutorial is for building a simple web application for sending e-mail message using the key technologies in Java EE platform: JSP, Servlet and JavaMail. Download the application as Eclipse project.
