Using Google Mail as your local SMTP server

As a server-side developer you are often sending emails from your web application, whether those emails be for debugging/exception handling or actual application functionality (such as a contact form etc).

Although some developers decide to turn off mail debugging locally (and instead view the errors inline), you pretty much always have the need to send emails from your development environment.

In the past I have either connected to a staging mail server or used a free SMTP server (installed locally on my workstation) like MailEnable. Well today Marko Tomic let me in on something which is probably already well known! You can setup GMail as an SMTP server in ColdFusion Administrator :)

What this means is you now don’t have to bother installing your own SMTP server or getting mail details from your systems administrator…you can just use your very own gmail account! Nice.

Note that I did also google this a bit and found a couple of posts including this one suggesting you use TLS (via the Administrator or cfmail attributes), but I needed to use SSL instead. I had no success with TLS.

Also reading the docs I’m not sure if this will work pre-CF8, as SSL and TLS were added as attributes in CF8.

Below are some examples of setting this up either in Administrator or in code, note the port number is not 25 as is the default, instead you must use port 465:

ColdFusion Administrator - mail

And in CFML:

<cfmail to="me@wherever.com" subject="Read me" from="you@wherever.com" server="smtp.gmail.com" useSSL="true" username="gmailUsername" password="gmailPassword" port="465">
	This is a test email!
</cfmail>

The nice thing about doing this in ColdFusion administrator (apart from not having to specify a cfmail server and username/password etc in your code) is that you can verify your connection to the SMTP server.

Post a Comment or Leave a Trackback

5 Comments

  1. November 13, 2007 at 2:25 pm | Permalink

    Yeah I was totally stoked when CF8 had SSL support. No more having to jump through hoops to get mail to send from my local dev box when testing.

  2. March 1, 2008 at 7:00 pm | Permalink

    Do i use my freeola user name & password

  3. December 7, 2010 at 8:25 pm | Permalink

    Thanks for the info, I can stop trying to get my local SMTP server to work now. Cheers!

  4. eremiya
    May 2, 2011 at 3:33 am | Permalink

    Hi,
    great post!
    It seems that the “from” parameter will be replaced by your gmail email address and the “bounce” parameter as well. Is there a way to go around that?

  5. John Sieber
    July 21, 2011 at 6:19 pm | Permalink

    I’m also wondering about the from and fail-to values. Are these both replaced by the account that is being used for authenticating to the gmail account?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*