Sending Email through GMail

In my last 2 posts I have shown you how to send SMTP email using Java. But I still haven’t shown how to send an Email through a secured SMTP server. To do so I’ll show you how to use GMail secured SMTP server to send Emails. Take a look at this class: The basic is the same, like sending a simple SMTP message. What’s different here is the creation of the Session object in the function getGmailSession(). The Session object is created with much more properties and with the Authenticator which holds the authentication properties. You will also need the mail.jar that can be found here. download source