gmailI noticed that when sending an email using Google’s SMTP server, all emails sent will automatically be saved in the Sent Items folder. So if your old code for example uses an IMAP server to save the email sent to the Sent Items folder, you could add an if conditional statement to see if the SMTP server used is GMail or not.

If it is, then it is best to ignore the IMAP code to store the sent email in the Sent Items folder. I tried to still use the IMAP code when I used Google’s SMTP server to see what would happen and it gave an exception.

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