Sending E-Mail Using GMail SMTP via Apache Commons Emails

GMail provides a handy and reliable SMTP mail server for your program / script. Following are GMail SMTP configuration settings:

  • SMTP Host Name:
  • SMTP Port: 587
  • TLS Enabled: Yes
  • Username: <your GMail email>
  • Password: <your gmail password>

In Java you can use commons-email to simply send an E-Mail using your GMail account.

First add commons-email jar into your classpath. If you use Maven, simply add following dependency (or newer version if any):


Following example assumes your GMail email is and password abcd1234.

Email email = new SimpleEmail();
email.setAuthentication("", "abcd1234");
email.setFrom("", "John Doe");
email.setSubject("Hi this is testing email only");
email.setMsg("Hello there testing to send email from GMail");

Note that by default GMail only allows email to be sent from your address (, you cannot send as somebody else for security reason. You need to perform additional configuration to allow external email to be sent via your GMail account.


One thought on “Sending E-Mail Using GMail SMTP via Apache Commons Emails

  1. Pingback: hMailServer for Outbound Only SMTP Server | Otherwise I'll Forget

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s