In case you encounter this error message when using JavaMail to connect to, say, GMail’s SMTP server, there is one property that needs to be present, mail.smtp.starttls.enable = true.

If, however the same error message persists, the following properties need to be added in order for this to work.

  • mail.smtp.socketFactory.port = 465
  • mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
  • mail.smtp.socketFactory.fallback = false

There, that should fix that annoying STARTTLS error message using JavaMail.

To Save email in your Sent Items folder using JavaMail, you need to add additional code after your email is sent. If you are connecting to GMail’s SMTP server, there is no need to since it automatically saves it to the Sent Mail folder. If you are connecting to some IMAP server, like an Exchange server, then you need to add the following code after your code that sends the email using SMTP.

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