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
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.
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.