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...

tags: , ,

  • http://www.k9hours.com Bhaskar Roy

    Problem is with InternetAddress(from_email, from_name)

    It doesn’t show from_email in recipient’s mail box, shows user gmail address.

  • http://tech.chitgoks.com tech

    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

  • http://tech.chitgoks.com/2009/01/01/javamail-send-mail-using-gmails-smtp-server/ indranilKundu

    Hello mesg send For Test

  • http://www.scriptomaniac.org Nulled Scripts

    Nice post..Keep them coming :) Thanks for sharing.

  • alvaro01

    change bcc for bcc_mail :)

  • http://tech.chitgoks.com tech

    @alvaro01: thanks for pointing out this typo ;)

  • Mr Big

    Thanks alot for your help.
    Your tutorial really helpful.
    Good job guy.

    • http://tech.chitgoks.com tech

      @mr big: thanks