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 email hosting 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").

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? :)

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:

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.

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

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

Re: Using Google as your CF Mail Server

Wow, I certainly appreciate this information!

The configuration I am using for my clients is to utilize multiple mailserver domains, per the input from Hatem Jaber above. (THANK YOU!!) They're using MX7.

Within these domains, I also need to utilize a variety of email "From" accounts within each application, so the default "From" sender issue where the mailserver's email account was shown as the From was definitely sub-optimal.

Extrapolating this to my scenario, I added my clients' other necessary email senders as alternate emails to their primary SMTP account. Google does not require you to select any of these alternates as the default, and you can specify a desired reply-to for each. In my case, each of these was a nickname to a single account.

All you need to do is dispatch a verification message to each alternate address and input the verification code it sends in the primary account. Once that's done, then you will be able to use any of those emails as the From param in CFMAIL.

One note: the email address is case-sensitive, so you must reference it in CFMAIL exactly as you established it in Google Apps.

Thanks, this worked great. One thing I would note is that even if all of your e-mail settings are hard-coded in files, you can still use the "Server Settings / Mail" section of the ColdFusion 7 admin UI to help test if the connection is working. Enter the full string in the "Mail Server" box, check the box for "Verify mail server connection", and then click the "Submit Changes" button. If it says "Connection Verification Failed" then the string will not work in CFmail. If it says "Connection Verification Successful" this seems to confirm that you have access to Google and have provided a valid Google Apps account.

Posted by Mike on September 7, 2010 at 4:02 PM

Re: Using Google as your CF Mail Server

This worked great on 6.1! Same issues as other guys. Can't run SMTP from a machine running off a cable connection due to SPAM flags, so hosting web is ok as long as I can use GMail to host domain emails. Be sure to "reload" the stunnel service after you change your config file. I'll try the multiple user capability next!

Posted by Steve Fazekas on September 24, 2010 at 2:51 PM

Re: Using Google as your CF Mail Server

For those of us dinosaurs still tied to MX7, I just wanted to re-emphasize Steve Fazekas' comment re: reloading stunnel service!!

I am in the finishing stages of moving clients from a Windows dedicated server to a Virtual dedicated server. Thanks to the info of this post, I'd gotten CFMAIL to work properly with Google Apps mail on the other server several years ago.

Moving to the new server, however, I noticed that, even with STunnel installed and configured, the mail was undeliverable. I also noticed that there was a bunch of undeliverable mail that had been brought over from the old server. So, at some point, "something" had changed and STunnel service had not been reloaded on that other machine.

I reloaded the STunnel config on the new machine, sent a test message from within one of the new server's applications, and things functioned properly. So, yes, RELOAD!! Thanks again to everyone for your contributions to this topic. There would have been NO WAY to have engineered this configuration without your help!

Posted by hlharkins on October 9, 2011 at 10:24 AM

Re: Using Google as your CF Mail Server

TeamSite, is designed for creating complex intranet and Internet web applications. Their document management system, Work Site, stores, indexes, organizes, and searches documents including email messages. Other products include OpenDeploy and LiveSite.