76
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
- SendMail.java , 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.
- Mailer.java , a java class that contains send method to send the emails to the mentioned recipient.
index.html
SendMail.java
Mailer.java
download this example (developed without IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
Next TopicHow To Write Data Into PDF Using Servlet