How to Send Email in Java Using SMTP?

Here you will learn how to send email in java using smtp.

JavaMail API provides the functionality for sending email. The process involves following three step.

  1. Get Session Object
  2. Compose Message
  3. Send Message

For sing JavaMail API we have to import jars mail.jar and activation.jar.

Download the jars from below link and import in your project.

Download: http://www.javatpoint.com/src/mail/mailactivation.zip

How to Send Email in Java Using SMTP?

Image Source

Send Email in Java Using SMTP Example

Below is the Java program to send email.

Make sure to change the host name, user name, password and port number according to your email provider.

If everything goes fine then you will see “Message Sent!!!” in console.

Note: Disable antivirus in your system otherwise it will cause problem in sending mail.

Above java send email example program is self explanatory, if still you are facing any problem then ask your queries in comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *