I’ve been gone for awhile. I mean, not really, just from A Better Geek. I met a special someone, so that took up a lot of my time. Then said Special Someone got a job with IBM in Virginia, and we packed up and moved 700 miles to Fairfax from Lafayette back in mid-September 2009. I’m looking for work and spending my time being a server administrator, because we decided to go for Verizon Business FiOS and are hosting everything (including our websites) from our home.
Let me tell you, this has been one huge educational experience that never seems to end. My server is now running my LAN’s internal DHCP and DNS. It’s also a game application server, an internal samba file server, and an internal and external web server.
One of the things apps like WordPress, PunBB, and other content systems use is email. I’ve already discussed in the past how to make sendmail in Linux play nicely with Apache and PHP, but I realized that things were changing as I started migrating our websites and projects to an entirely different environment – Windows Server 2008 R2 Enterprise and IIS 7.0. There are some growing pains, but at least it gives me a lot to write about!
Anyhow, I realized shortly after the migration of Dan’s game servers (and related websites) that the server wasn’t sending mail. Since, you know, I hadn’t set up an SMTP service in Windows. “So what?” I thought to myself, “I’ll just install it and everything will be hunky-dory, right?”
It turns out that in 2009, every large mail service provider on the Internet really hates relaying email that comes from suspicious locations, including IP addresses that are part of residential ISPs. Even though we have a static IP address through Verizon Business, it’s still part of Verizon’s greater IP pool – which includes all their dynamic IPs for residential FiOS and DSL services.
Google blacklisted me the second I tried to send a message to an @gmail.com address. It was just downhill from there. I found out from some people on IRC that I needed a reverse DNS entry if I wanted anyone to relay my email, so I called up Verizon and got that taken care of. Yahoo, MSN, and AOL started relaying my mail, but Google kept delaying delivery, claiming that an “unusual amount of unsolicited email” was coming from my IP address.
After many hours on IRC and doing additional research on Google, I decided it probably wasn’t worth it to keep wrestling to make the big mail servers of cyberspace deem my rinky-dink little server worthy of their approval. It was time to look for other solutions.
I decided right from the start that I did not want to deal with hosting mail. I have no interest in trying to mitigate mass quantities of spam. My friend Julie over The Gadgeteer got on the Gmail Apps boat and moved her own email over to Google. It seemed appealing enough, so I decided to give it a shot. Google Apps offers a free version to cheapskates like me who can’t or don’t want to pay yet another monthly fee. The free version includes Google mail, calendar, sites, chat, and docs. Works for me!
Google was brilliant about the whole thing. I signed up, and when I clicked in the web-based control panel to set up email, it automagically discovered that my domain (polatrite.com, in this case) was registered with 1and1.com, so it directed me to a 1and1-specific how-to on setting up the MX records for my domain. About 18 hours later, 1and1 and Google had both updated their servers and records, and I was in business. Now it was time to figure out how to make my web server send email through Google’s SMTP servers.
Which is why we’re here today. If you’re still paying attention, that is. As always, this is a little screenshot-heavy, so hit the jump to carry onward.
First off, if you haven’t already, you need to install the SMTP service in Windows. Start by opening up your Server Manager. Click on Features in the lefthand pane, and then “Add Features”:
Make sure that both SMTP Server and SMTP Server Tools are checked. Windows, being the wizard-happy operating system that it is, will walk you through the steps to install SMTP, including installing any dependent services you may need. Once that’s done, we can continue to actually making your mail route through Google’s servers.
The SMTP standard allows for something called smart hosting. Essentially, an SMTP service set up with a smart host actually sends its mail to another SMTP server, which then relays the mail from there into the scary unknowns of cyberspace. This is exactly what I needed – by relaying my mail through Google’s servers, the outside world would see my mail as Google-sent, and nobody in their right mind is going to block Google mail (theoretically).
Before we can set up our server, we need enable IMAP in Gmail. Login to the Gmail web interface, and click Settings in the top right corner of your browser window. Select the Forwarding and POP/IMAP settings tab, and make sure Enable IMAP is selected. If it’s not, select it and save your changes.
Now that we have permission to access our mail outside of Google’s web interface, we can set up the server.
The SMTP service available in Windows Server 2008 is actually managed through IIS 6.0, not 7.0. Fire up the IIS 6.0 manager by going to Start > Administrative Tools > Internet Information Services (IIS) 6.0 Manager. Under your server, you’ll see a little hideous 16-color envelope icon. This is your SMTP virtual server, which IIS uses to send mail. Right-click on it and select Properties.
Click the Delivery tab, and then the Outbound Security… button. We want Basic Authentication. Enter your Google account credentials, and make sure TLS Encryption is enabled, since Google’s SMTP servers require SSL.
Click OK, then the Advanced… button on the same tab. Here’s where we set up our smart host that our own SMTP service will use to relay email. Enter the domain of your site under Fully-qualified domain name, and use smtp.gmail.com as the smart host.
Click OK. Now we’re going to enable logging, which will be critically important to ensure that your email is being accepted by receiving SMTP servers. Click the General tab. Make sure the Enable logging box is selected, and choose your log format. I’m not all that well-versed on what the different formats are. “Microsoft IIS Log File Format” has been working fine for me. Click Properties… next the log format drop-down to choose where your logs are going to reside. Click OK.
Double-check everything, and click OK to apply your new settings. I went ahead and restarted the SMTP service, just to make sure that everything was working correctly.
Now you can test your server and see if everything is working. I made a simple ColdFusion page that sent a test message to Gmail, AOL, Yahoo, and MSN (just to double-check!). It worked perfectly.
But…wait! Even though I had set the “from” parameter of the cfmail tag to come from my Gmail address, Google overrode this and used my polatrite.com email address as the “from” address in the message header. I don’t want all my websites sending mail from this one address! A Better Geek and Polatrite Gaming are two completely different entities, so I needed to remedy this right away.
Never fear, Google is here to save the day! Gmail has this neat feature, available in normal Gmail accounts and Google Apps accounts, that allows you to send mail from other mail accounts right from inside the Gmail web interface. It’s easy to set up, and it works well.
Log back in to your Gmail web interface, and go back to your settings. Navigate to the Accounts settings page. Select Add another email address you own in the Send mail as section, which will pop up a new window. Enter the name and email address you want to display on mail sent from this account.
On the next page, select to send the mail through the secondary address’s SMTP servers. It’s important to keep in mind that this will only work for email accounts that have given you permission to send mail externally (e.g. not through the webmail interface) – Yahoo and MSN/Live do not provide this functionality for free email accounts. However, all Gmail accounts and Google Apps accounts allow for external SMTP access. Enter smtp.gmail.com as the SMTP server, select port 465 or 587, and make sure Always use a secure connection (SSL) is enabled. Enter the username and password for this secondary email account, and click Add Account.
After you’ve added your account, Google will email that address with a confirmation message. Click the link in that email to validate that you are authorized to use it, and Google will enable that account in Gmail. Once your second account is activated, you can send mail from your websites with this second email address as the “from” address, and Google will send it accordingly.
Google does have some limitations on what is allowed with the free version of Google Apps, and it’s important to keep this in mind for your websites. A single message can have a maximum of 100 recipients. Additionally, you can send mail to a total of 500 recipients per day. If you have a very active server, you’re probably going to be better off running your own mail server or paying for a larger-scale male service (Google Apps Premier allows up to 2000 recipients daily), but for small-time stuff like I’m managing, this is going to work just fine. I’ll still try to get my server off Google’s mail blacklist so that I can eventually use my own SMTP server, but in the meantime, this is a fast and easy way to get Windows ready to go for sending mail through web applications.