Categories
Contact Doug!
Learn About Doug!
View Doug Boude's online resume
updated 11/18/2009

View Doug Boude's profile on LinkedIn
Link to me!

Follow Doug Boude on Twitter
Follow me!

Be Doug's friend on Facebook
Befriend me!
(I promise not to follow you home)
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...
Web Hosting

<< April, 2014 >>
SMTWTFS
12345
6789101112
13141516171819
20212223242526
27282930
Search Blog

Recent Comments
Re: Basic Ajax Select List Filter in PHP (by good at 2/04 5:26 AM)
Re: Family Law: The Weapon of Choice for Woman Scorned (by swalker at 2/03 2:15 AM)
Re: Approaches to Building Strings: The Imploding Array (by bantal silikon at 2/01 9:44 PM)
Re: Disappearing IE Popup Window During Save/Open Dialog (by AddisonDean at 1/15 9:59 AM)
Re: My Top 20 Life Lessons for Boys and Young Men (by Alex at 1/13 8:45 PM)
Re: Array Loop Modifications in CFSCRIPT (by Alex at 11/25 11:18 AM)
Re: Array Loop Modifications in CFSCRIPT (by Abram at 11/14 11:32 PM)
Re: Recursive Functions in ColdFusion (by Dwayne at 10/25 3:47 PM)
Re: Porting Coldfusion Code to Mura (by dh at 10/16 10:14 AM)
Re: Viewing Option Text (in IE7) that's Wider than the Select List (by Devil May Cry at 9/26 1:38 AM)
Re: Why I Hate ORMs (a solicited rant) (by guideX at 9/12 11:38 PM)
Re: Recursive Functions in ColdFusion (by KP at 8/08 7:13 PM)
Re: American Airlines, YOU SUCK! (by Alison at 7/23 4:48 PM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Harshad at 7/11 9:17 AM)
Re: Disappearing IE Popup Window During Save/Open Dialog (by LZ at 4/20 7:58 AM)
Re: Create Dynamic WHERE Clauses in PHP (by pooja at 3/20 7:29 AM)
Re: Just What IS a 'Service Layer', Anyway? (by EugenK at 3/07 7:56 PM)
Re: Using Google as your CF Mail Server (by 5starwebteam.com at 2/25 1:27 AM)
Re: Why Provide for Service layer objects in CFWheels? (by Steven Benjamin at 1/25 11:43 AM)
Re: What is an 'Advanced' Coldfusion Developer? (by ColdFusion Developer at 12/24 5:14 AM)
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

04 February 2008
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 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
coldfusion email error log

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


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

coldfusion mail server settings

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

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.



Posted by dougboude at 12:13 PM | PRINT THIS POST! |Link | 15 comments
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.
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
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.
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]
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.
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.

After foraging around a bit, I found some instructions for adding additional authorized sending addresses to a given gmail account. http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=22370.

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.

Within the recipient's inbox, the message will display the appropriate From email address of the sender. Once the message is opened, it will show the From as [yourSMTPAccount@domain.com] on behalf of [yourIntendedFromSender@domain.com]. The reply-to will be [yourIntendedFromSender@domain.com].
Posted by hlharkins on October 27, 2009 at 7:37 PM

Re: Using Google as your CF Mail Server
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.
Posted by 5starwebteam.com on February 25, 2013 at 1:27 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

Zero plus Ten equals
Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!