JavaMail: Send Mail Using Gmail’s SMTP Server

Sometimes having our own SMTP server can cause problems especially the newbie ones. If our SMTP server is being detected by such spam security sites like Spamhaus as a probable spam server, emails that we send to recipients will eventually be blocked. We would have to register our server to these sites so that they would get unblocked. If you are too lazy to wait or want to avoid the hassle of this kind of dilemna, you can actually use GMail’s SMTP server.

The code below sends an email using JavaMail, Java’s mail technology API to send and receive emails. It also includes a Reply-To Email parameter in case you want your Reply-To email address to be different. The other parameter option is to specify if you want to email to be sent at text or HTML. Just input html as the value if you want to send the email as HTML.

Note that connecting to GMail’s SMTP server requires you to authenticate first so you would have to use a GMail account before transactions push through.

Related Posts Plugin for WordPress, Blogger...


  1. hi bhaskar, im confused. the recipient’s email address is shown instead of the sender’s email address?

    can you please paste the code here how you called the method? maybe the values were not placed correctly according to the parameter ordering

Leave a Reply

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