Send email using gmail SMTP server in JAVA

Sending JavaMail – GMail via TLS


This example will show you how to use JavaMail API method to send an email via Gmail SMTP server, using both TLS connection.

you need only one dependency jar – mail.jar download from here mail.jar (After downloading extract the zip file to get mail.jar)

Below example uses GMail SMTP server-
Mail authentication is set to true and you need to give sender’s email and password. It is mandatory, you cannot send email anonymously using GMail SMTP.
You can send email to multiple recipient .
Sample uses HTML email as content type, if you want normal text type then don’t pass any content type.
Change FROMUSER, FROMUSEREMAILPASSWORD and add recipient address in toEmailList.



After running this code, check your email inbox.

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

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