Send Email in jsp ( java server pages) web application using JavaMail

Send Email In Jsp

In this tutorial I will explain how to send email in jsp and solutions of problems occurred when send email from application. In this tutorial I will also explain the complete procedure to implement sending email without any error. If we use email sending facilities in project or application then project become more efficient and attractive. But to implement sending email in project is more difficult task and get many errors. So this encourage me to publish this tutorial.

Question Answer of send email in jsp

Question:-Use of send email in project or web application?
 Ans:- Before start see procedure of sending email in jsp application we need to know about use of sending email in project. We can use sending email in project or application or web application for feed back support and for contact support system in project. Best use of sending email is if your application is support login system then the password is send to email of user when the signup or change or password. Above were only few points which came to my mind but we can use send email many more area.

Question:-What is need to send email? (Requirements)
Ans:-  To send email we need following things, which is as
1. JSP Editor:- First we need editor for editing files, which may be *.jsp, *.html, *.java etc. You can use any editor but if you use “Macromedia Dreamweave” software then you easily edit files because of this provide the view of edited page.
2. Application server or Servlet container:- To run *.jsp, *.java files server is required. You can use Tomcat server but if you use Sun Java™ System Application Server Platform.In this better platform provide to run *.jsp files.
3. javaMail jar file:- If your JDK with J2EE not contain javaMail( mail.jar) then you need to download it. You can download it here Sun’s JavaMail. If you download it then you need to put it into lib folder of server. If you want to use it only for your application then you can put it into WEB-INF/lib.
4. SMTP host address:- SMTP host address is required to send email over internet from your application. SMTP stands for simple mail transport protocol. It allows us to send emails. If you have domain email and your hosting provide smtp services emails then you can use it.
If you not any hosting emails then you can use free email host addresses just like
gmail, yahoo etc.
smtp host address of my site is- smtp.computerscienceartilce.in
For gmail- smtp.gmail.com
yahoo- smtp.yahoo.com
You can use localhost as smtp host.

How to send email?
Ok now lets see how to send email.
To send email you need minimum two files first is data entry file and second is send process.
Data entry files may be simple html file or jsp file. In this file we use form to enter required data.
lets see the DataEntry.jsp file preview.

data entry page preview of send email in jsp

data entry page preview of send email in jsp

Download this DataEntry.jsp file.

Second file is send process file, it must be *.jsp file because of in this jsp scripts is used.

Download sendProcess.jsp file.

In this file some term must be change according to your host and other.
First is host this must be your hosting address of smtp.
port port is may be 25, 587, 465. this is depend upon the use of connection.
means that the for localhost you can use port 25.
for TLS connection use port 587 and for SSL connection port is 465.
Next term change is username and password. User name of your mail hosting and password.

Question:- Common error occurred during send email.
And:- During send email many errors occurred. some of is explain here and also solution of that problems.

1. javax.mail.AuthenticationFailedException: failed to connect
Ans:- This type of error is occurred due to wrong username and password to authenticate to host server.

2. java.io.FilePermission (read, write). setting error.
Ans:- This error is due to JDK not permit to read and write anything by application. This error is can solve grant permission using policytool.exe in jdk bin folder.
If you have any problem then comment here. I will help you.

82 Comments
  1. April 6, 2012
    • August 4, 2013
  2. April 10, 2012
  3. April 11, 2012
  4. April 11, 2012
  5. April 11, 2012
  6. April 11, 2012
    • November 9, 2013
  7. April 13, 2012
  8. April 13, 2012
  9. April 13, 2012
  10. April 13, 2012
  11. April 17, 2012
  12. April 17, 2012
  13. April 23, 2012
  14. April 23, 2012
  15. June 9, 2012
  16. June 14, 2012
    • June 14, 2012
  17. June 21, 2012
    • June 22, 2012
  18. June 22, 2012
    • June 22, 2012
      • March 21, 2013
        • March 22, 2013
  19. August 28, 2012
    • August 28, 2012
  20. September 21, 2012
  21. October 5, 2012
    • October 7, 2012
  22. January 8, 2013
  23. January 10, 2013
  24. January 15, 2013
  25. January 15, 2013
  26. January 15, 2013
  27. January 21, 2013
    • January 31, 2013
  28. February 1, 2013
    • April 13, 2013
  29. February 6, 2013
  30. February 23, 2013
  31. February 23, 2013
  32. March 6, 2013
  33. March 7, 2013
    • March 7, 2013
  34. March 17, 2013
  35. March 22, 2013
  36. March 25, 2013
    • March 26, 2013
  37. March 25, 2013
  38. March 26, 2013
  39. March 26, 2013
  40. March 28, 2013
  41. March 30, 2013
    • March 30, 2013
      • March 31, 2013
        • March 31, 2013
        • April 1, 2013
  42. March 31, 2013
  43. April 5, 2013
  44. April 8, 2013
  45. April 9, 2013
  46. April 9, 2013
  47. April 30, 2013
  48. July 1, 2013
    • July 27, 2013
      • July 31, 2013
        • July 31, 2013
  49. July 6, 2013
  50. September 18, 2013
  51. September 26, 2013
  52. October 5, 2013
  53. October 5, 2013
  54. October 5, 2013
  55. November 9, 2013
  56. March 19, 2014
  57. March 26, 2014
  58. May 3, 2014
  59. November 25, 2014
  60. March 15, 2015
    • March 16, 2015