Email sending using Servlet




In this example, we will see how to send an email in Servlet application. We will be using the JavaMail API that provides all the classes required for sending an email. JavaMail API encapsulates two important packages javax.mail and javax.mail.internet. These packages provide classes that can be used to send and receive simple emails. You simply need an Internet connection to send email using this simple Application.



Following the names of files to be created :
  • Sent_Mail.java : Servlet java file which controls the request and response. It will invoke the send() method of Mail.java class that we have created to send the email.
  • Mail.java : A java class that contains method to send mail.
  • web.xml : In that give servlet name and url pattern.
  • index.html : Will get the input from user.


1) Sent_Mail.java :









2) Mail.java:







3)web.xml :















4)index.html :


  • Right click on mouse and
  • Select “Run As”
  • Click on “Run on Server”.








  • Copy “URL” and paste in a browser and
  • Enter the valid e-mail id's “From” and “To” and
  • Write Text
  • Click on “Submit” button
  • You will see the output is “Mail sent successfully” on that page.




Conclusion: As Shown, it is very useful to send an email in Servlet application.




          Further any queries contact me,


Thank you,

Ramakrishna Koppala,

krishna.rama107@gmail.com

Mouri Tech Pvt Ltd,


www.mouritech.com.





Comments

Popular posts from this blog

Sending email in JAVA Servlet