Javatpoint Logo
Javatpoint Logo

Sending email through JavaMail API in Servlet

The JavaMail API provides many classes that can be used to send email from java. The javax.mail and javax.mail.internet packages contains all the classes required for sending and receiving emails.

For better understanding of this example click steps for sending email from javamail api

For sending the email using JavaMail API, you need to load the two jar files:

  • mail.jar
  • activation.jar
download these jar files or go to the Oracle site to download the latest version.

Example of Sending email through JavaMail API in Servlet

Here is the simple example of sending email from servlet. For this example we are creating 3 files:

  • index.html file for input
  • , a servlet file for handling the request and providing the response to the user. It uses the send method of Mailer class to send the email.
  • , a java class that contains send method to send the emails to the mentioned recipient.


Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA