Using Google as your CF Mail Server
Ah, sounds like a no brainer, right? Why even do a blog post on such a thing, right? Because Google requires that an SMTP connection be encrypted...something that CFMX7 just doesn't do all by its lonesome. I need to vent a little, so here's my story followed by some useful info....
It's extremely late on a Sunday night and you're in the final final stages of a site migration for a client. Their "under construction" sign says that everything will be back online and kosher at 7 am Monday morning, so you're addressing one of the last things on your list: setting up the client's mail server.
It made it to the end of the list because of the fact that they're using a third party to relay their mail: Google. Now everybody knows Google's reputation for being logical and actually making sense most of the time, so how hard can it be to make sure that Coldfusion is pointing to the client's Google SMTP, especially when the client said it was a piece of cake when they set it up the first time? You figure out later that the person who told you that wasn't actually the person who set it up to begin with, as the passing time turns into a couple of hours and you still haven't sent a successful email.
(Here comes the venting part I mentioned...) You know what chaps my hide, grinds my gears, gets my goat (I wonder where that one evolved from), et al? It's the same thing that gets my goat most of the time, the incredibly cryptic nature of some things that ought to be simple and all of the other people out there on the net who managed to get it to work but insist on only sharing yet more cryptic or worse yet, elusive, information on how they did it (if they share any of the "hows" at all!). I want to share with you my journey, at 2 am on a Sunday night, to learning how to set up a secure tunnel to an smtp server for the purpose of using Google's smtp server for sending email. I want to do this, ALL IN ONE BLOG POST, just in case anybody else out there EVER finds themselves in the position I was...I wouldn't wish such a frustrating, elusive game of Clue on any other person.
CUTTIN' TO THE CHASE, if you're trying to use Google's smtp server to send mail and you're seeing errors like this one

in your mail log file, it's telling you that Google requires you to authenticate to its smtp server via an SSL connection, and any Coldfusion version below 8 (I read a short post saying that version 8 could handle such things, but the poster FAILED to give any other clues as to how to implement it...sheesh) can't do that all by its lonesome. So, we need an intercessor, a little service running on the web server that will intercept requests to ports internally then reroute the request to an outward-facing port using a secure connection. That intercessor is called 'STunnel' (though there were a couple of other equal products I came across). In a numbered list then, here are the steps a body needs to do in order to make it work:
1. Make sure you have a Google email account.
My client is signed up to use Google Apps, which includes an email server. Here's a starter link for you: https://www.google.com/a/help/intl/en/admins/editions.html
2. Make sure you know the username and password for the Google email account
3. Download and install a program called STUNNEL (latest windows exe can be found on this page: http://www.stunnel.org/download/binaries.html)
4. Edit Stunnel's configuration file (the default config file is in the stunnel directory, and is called "stunnel.conf").
5. Empty out the config file and paste in the following values:
6. Go into your CF Administrator, to the mail settings, and enter the appropriate values according to the illustration and your own username and password

(note: 127.0.0.1 is not a placeholder value in this blog post: use that value! Also, notice the port number used, 259; it's the same number in the stunnel.conf file for accepting SMTP mail.)
7. Go to the stunnel directory under Programs and choose to install it as a service, then run it as a service.
8. Go to your services list and make sure stunnel is running.
9. Just for fun, restart the CF service
10. Execute a template you made that has a cfmail tag set up similar to the following:
11. Log in to your google mail and look in your sent items folder. The email you sent should appear there tout suite. (Google apps allows you to point a subdomain to their email server...my client's is similar to "mailbox.clientdomain.com", fyi)
12. if you don't see the email in the sent items folder, check CF's mail log and make sure it didn't generate a STARTTLS error
If you do all of this and it still doesn't work, I'm afraid I have no more information for you. BUT, if you run into additional issues and DO manage to fix them, please post that info back to the comments area of this post for the benefit of others!
Okay, I feel better now. Being forced to invest SO much time and energy, at 2 am, and then finding nothing but a few nearly useless clues here and there to go on can really drain a person emotionally, ya know? :)
Doug out.
It's extremely late on a Sunday night and you're in the final final stages of a site migration for a client. Their "under construction" sign says that everything will be back online and kosher at 7 am Monday morning, so you're addressing one of the last things on your list: setting up the client's mail server.
It made it to the end of the list because of the fact that they're using a third party to relay their mail: Google. Now everybody knows Google's reputation for being logical and actually making sense most of the time, so how hard can it be to make sure that Coldfusion is pointing to the client's Google SMTP, especially when the client said it was a piece of cake when they set it up the first time? You figure out later that the person who told you that wasn't actually the person who set it up to begin with, as the passing time turns into a couple of hours and you still haven't sent a successful email.
(Here comes the venting part I mentioned...) You know what chaps my hide, grinds my gears, gets my goat (I wonder where that one evolved from), et al? It's the same thing that gets my goat most of the time, the incredibly cryptic nature of some things that ought to be simple and all of the other people out there on the net who managed to get it to work but insist on only sharing yet more cryptic or worse yet, elusive, information on how they did it (if they share any of the "hows" at all!). I want to share with you my journey, at 2 am on a Sunday night, to learning how to set up a secure tunnel to an smtp server for the purpose of using Google's smtp server for sending email. I want to do this, ALL IN ONE BLOG POST, just in case anybody else out there EVER finds themselves in the position I was...I wouldn't wish such a frustrating, elusive game of Clue on any other person.
CUTTIN' TO THE CHASE, if you're trying to use Google's smtp server to send mail and you're seeing errors like this one

in your mail log file, it's telling you that Google requires you to authenticate to its smtp server via an SSL connection, and any Coldfusion version below 8 (I read a short post saying that version 8 could handle such things, but the poster FAILED to give any other clues as to how to implement it...sheesh) can't do that all by its lonesome. So, we need an intercessor, a little service running on the web server that will intercept requests to ports internally then reroute the request to an outward-facing port using a secure connection. That intercessor is called 'STunnel' (though there were a couple of other equal products I came across). In a numbered list then, here are the steps a body needs to do in order to make it work:
1. Make sure you have a Google email account.
My client is signed up to use Google Apps, which includes an email server. Here's a starter link for you: https://www.google.com/a/help/intl/en/admins/editions.html
2. Make sure you know the username and password for the Google email account
3. Download and install a program called STUNNEL (latest windows exe can be found on this page: http://www.stunnel.org/download/binaries.html)
4. Edit Stunnel's configuration file (the default config file is in the stunnel directory, and is called "stunnel.conf").
5. Empty out the config file and paste in the following values:
client = yes
debug = debug
[pop3s]
accept = 127.0.0.1:1109
connect = pop.gmail.com:995
[smtps]
accept = 127.0.0.1:259
connect = smtp.gmail.com:465
debug = debug
[pop3s]
accept = 127.0.0.1:1109
connect = pop.gmail.com:995
[smtps]
accept = 127.0.0.1:259
connect = smtp.gmail.com:465
6. Go into your CF Administrator, to the mail settings, and enter the appropriate values according to the illustration and your own username and password

(note: 127.0.0.1 is not a placeholder value in this blog post: use that value! Also, notice the port number used, 259; it's the same number in the stunnel.conf file for accepting SMTP mail.)
7. Go to the stunnel directory under Programs and choose to install it as a service, then run it as a service.
8. Go to your services list and make sure stunnel is running.
9. Just for fun, restart the CF service
10. Execute a template you made that has a cfmail tag set up similar to the following:
<CFMAIL
TO="dougboude@gmail.com"
FROM="admin@myclient.com"
SUBJECT="test email from server"
TYPE="HTML">
testing
</CFMAIL>
TO="dougboude@gmail.com"
FROM="admin@myclient.com"
SUBJECT="test email from server"
TYPE="HTML">
testing
</CFMAIL>
11. Log in to your google mail and look in your sent items folder. The email you sent should appear there tout suite. (Google apps allows you to point a subdomain to their email server...my client's is similar to "mailbox.clientdomain.com", fyi)
12. if you don't see the email in the sent items folder, check CF's mail log and make sure it didn't generate a STARTTLS error
If you do all of this and it still doesn't work, I'm afraid I have no more information for you. BUT, if you run into additional issues and DO manage to fix them, please post that info back to the comments area of this post for the benefit of others!
Okay, I feel better now. Being forced to invest SO much time and energy, at 2 am, and then finding nothing but a few nearly useless clues here and there to go on can really drain a person emotionally, ya know? :)
Doug out.
Subscription Options
You are not logged in, so your subscription status for this entry is unknown. You can login or register here.
Re: Using Google as your CF Mail Server
Definitely saving this post for future reference. Awesome.
Posted by Ben Nadel on February 4, 2008 at 12:46 PM
Re: Using Google as your CF Mail Server
In CF8 when configuring the mail settings there is an option:
Enable SSL socket connections to mail server
Select this check box to enable SSL encryption on the connections to the mail server.
Check that and you can use GMail. I've done it in the past but now use spoolmail by Ray Camden.
Enable SSL socket connections to mail server
Select this check box to enable SSL encryption on the connections to the mail server.
Check that and you can use GMail. I've done it in the past but now use spoolmail by Ray Camden.
Posted by Sam Farmer on February 4, 2008 at 12:50 PM
Re: Using Google as your CF Mail Server
I ran into this with 7 as well. The only thing I was able to come up with was jscape. I have a post on it here:
http://www.roktech.net/devblog/index.cfm/2006/10/24/Cfmail-Google-Tools-For-Your-Domain-and-SPAM
Lucky for me, 8 fixes all of that....
Jason
http://www.roktech.net/devblog/index.cfm/2006/10/24/Cfmail-Google-Tools-For-Your-Domain-and-SPAM
Lucky for me, 8 fixes all of that....
Jason
Posted by jason on February 4, 2008 at 5:14 PM
Re: Using Google as your CF Mail Server
Doug,
Excellent post, helped me out a great deal, thank you!
To expand on this example, let's assume you have multiple sites running on the same server and all these clients your hosting have separate gmail accounts and they all want the same setup.
You can bypass step 6 and leave the mail settings in the administrator alone. Than in step 10 you would do this instead:
testing
I just tested this out to make sure it works before posting, it works great and I'm sure you can use multiple accounts if need be.
Hope this helps others who were suffering! The next task is to find something similar to Stunnel that can be installed or added to a shared hosting account to allow those who don't have a dedicated machine to setup somethign similar.
Excellent post, helped me out a great deal, thank you!
To expand on this example, let's assume you have multiple sites running on the same server and all these clients your hosting have separate gmail accounts and they all want the same setup.
You can bypass step 6 and leave the mail settings in the administrator alone. Than in step 10 you would do this instead:
testing
I just tested this out to make sure it works before posting, it works great and I'm sure you can use multiple accounts if need be.
Hope this helps others who were suffering! The next task is to find something similar to Stunnel that can be installed or added to a shared hosting account to allow those who don't have a dedicated machine to setup somethign similar.
Posted by Hatem Jaber on June 5, 2008 at 10:46 AM
Re: Using Google as your CF Mail Server
I used code tags to show the code, guess that doesn't work here, but this is the part that didn't show up on my post:
[CFMAIL
TO="dougboude@gmail.com"
FROM="admin@myclient.com"
SUBJECT="test email from server"
PORT="259"
MAILSERVER="[YOUR GOOGLE USERNAME]:[YOUR GOOGLE PASSWORD]@127.0.0.1"
TYPE="HTML"]
testing
[/CFMAIL]
[CFMAIL
TO="dougboude@gmail.com"
FROM="admin@myclient.com"
SUBJECT="test email from server"
PORT="259"
MAILSERVER="[YOUR GOOGLE USERNAME]:[YOUR GOOGLE PASSWORD]@127.0.0.1"
TYPE="HTML"]
testing
[/CFMAIL]
Posted by Hatem Jaber on June 5, 2008 at 10:49 AM
Re: Using Google as your CF Mail Server
Thank you very very much for this information, it has helped me greatly!
Posted by darwin on July 18, 2008 at 2:47 PM
Re: Using Google as your CF Mail Server
Thanks Doug. This helped me a lot!
This also works with the OpenBD / Jetty project.
This also works with the OpenBD / Jetty project.
Posted by Kevin Pepperman on August 30, 2008 at 6:36 PM
Re: Using Google as your CF Mail Server
Thanks Doug, Helped me too!!
Posted by wesdom on December 26, 2008 at 2:00 PM
Re: Using Google as your CF Mail Server
Great post, thanks Doug.
A few remarks which might help other CF users:
- Google changes the "From" address used in Coldfusion and replaces it by the registered email address (the one you use in the mail server settings in the CF administrator). In the preceding CF example, the recipient of the email won't see "admin@myclient.com" in the From, but he will see something like "myname@gmail.com". However, the reply address will be correct (admin@myclient.com)
- The same procedure can be used with other email systems like Yahoo (ATT, SBC). In fact, Yahoo allows you to add an alternate address (like admin@myclient.com or whatever you own), then you need to verify it. After this, you can use it as a "From" address in Coldfusion and the recipient will receive the email with this correct address displayed, not your main Yahoo email address (which would be the one used in the CF admin or in the CF code for the server).
A few remarks which might help other CF users:
- Google changes the "From" address used in Coldfusion and replaces it by the registered email address (the one you use in the mail server settings in the CF administrator). In the preceding CF example, the recipient of the email won't see "admin@myclient.com" in the From, but he will see something like "myname@gmail.com". However, the reply address will be correct (admin@myclient.com)
- The same procedure can be used with other email systems like Yahoo (ATT, SBC). In fact, Yahoo allows you to add an alternate address (like admin@myclient.com or whatever you own), then you need to verify it. After this, you can use it as a "From" address in Coldfusion and the recipient will receive the email with this correct address displayed, not your main Yahoo email address (which would be the one used in the CF admin or in the CF code for the server).
Posted by Paul Lovetech on January 9, 2009 at 11:20 AM
Re: Using Google as your CF Mail Server
Thanks Doug! I used this for AT&T Yahoo! and it worked like a charm for ColdFusion MX 6.1 Server. CFMAIL been down for 2 months until I found your article.
Posted by Ben on June 4, 2009 at 11:22 PM
