Java-programs

JAVA MAIL API - JSP PROJECT EXAMPLE

In this project, the user can enter receiver’s email ID, subject, body of email and then send the email using Java Mail API.

Note: Before using this project’s code you need to set sender’s email ID and password in sendemail.java . Only then this code will work. Also, remember to disable google account security incase you are using gmail id to send email and also don’t forget to check that javax.mail.jar is there or not. If it is not there and an error comes then you can download it from here and then add the jar file in libraries folder of your project.

Before using this project make sure to make following changes

Due to privacy reasons, in sendemail.java I have not given sender’s email and password. But if you are using this project then you must update this sendemail.java file and find following code lines there and correct it:

String myAccountEmail = “Write sender’s email here”;
String password = “Write sender’s password here”;

After you have written right sender’s email Id in myAccountEmail variable and right password of your sender’s email Id in password variable then you are good to go. Also, make sure that you need to disable security in sender’s gmail account settings also.

How to disable security to run this project

If you are giving your own (gmail) email id as sender’s email id then,

Project Structure

pic

Main Files of this project

Output Folder

First Page that appears after running this project

pic

Sending email

pic

If receiver’s email ID and your (own) sender’s email ID and password are entered correct then this emailsent.jsp page will be shown. Make sure before using this project you have written right sender email ID and password in sendemail.java file.

pic

Receiver email ID will receive email like below :

pic

If receiver email is NOT entered correct then this emailNotSent.jsp page will be shown.

pic

Output if wrong email was entered

pic