Tutorial: Sending email through Gmail
An introduction to using Gmail as your Email Service Provider
There are many reasons to consider outsourcing your email. Getting an email into someone’s inbox is not a simple matter these days. There are a million things you need to know to make sure an email actually makes it to the recipient and not into the junk folder. That’s why more and more people are opting to have an email service provider (ESP) take care of sending email for them. With an ESP, you let them keep up with all the blacklists and the whitelists. You can stop worrying about maintaining mail servers and start focusing on the real challenges of your business.
There are a few downsides to using an ESP. First, they are relatively expensive. For a good ESP, you are looking at paying thousands of dollars a year just to send a few emails. Secondly, most ESP’s are focused towards corporate bulk mailers instead of web startups that send lots of customized emails to one person at a time. This makes integration really awkward. Lastly, the ESP’s that have API’s don’t make it easy on you. It’s hard to find an ESP that will integrate nicely with your existing code.
Recently I decided to try using Google Apps for your Domain to send emails from our website. Google Apps offers many of the same benefits as an ESP, but they do it for free and code integration is a non-issue. So far, the results have been great and we’re not losing as many emails to spam filters anymore. I’m not an deliverability expert, but I learned a lot from fighting the email battle this past week. My goal with this tutorial is to share what I learned, so you don’t have to spend a week running all over the web to find it.
The step-by-step tutorial I wish I’d had a week ago:
Set up Google Apps for your domain
Google Apps for your domain comes in a free Standard Edition and a $50/user/year Premier Edition. I took advantage of their offer of one month free with the Premier Edition (mainly for their included tech support), but ultimately I decided that the Standard Edition more than meets my needs. Unless you’ve got some crazy integration needs, Standard Edition will probably do just fine.
Verify your domain
Verifying your domain allows GMail to send emails from your domain instead of on behalf of your domain. You can verify your domain name by either uploading a specific HTML file to your site, or by adding a CNAME record to your DNS records.
Create an account for each email address you want to send from
Google makes it easy to set up multiple accounts with an Excel spreadsheet upload. I’d recommend using the same password for each account to simplify your life and code. If you’re like me, the first thing you will want to do is sign in to each account and forward everything to an email address that you check every day.
Add Google’s MX servers to your DNS records
You will need to add these MX records for Google’s mail servers to your DNS records
Publish an SPF record that includes Google’s SPF record.
A lot of spam filters rely on the Sender Policy Framework (SPF) and Sender ID to decide whether or not to allow your message through or not. An SPF record is simply a DNS record on your server that has a list of IP addresses and domain names that are allowed to send emails from your domain name. In addition to listing the IP addresses of your own servers, you can also include the SPF record from another domain. In this case, we want to include Google’s SPF record to include an up to date list of their mail servers. If you are going to be sending mail from other servers besides google, I recommend you look over this list of common mistakes before you start playing around with your SPF record. You should be particularly careful if you have existing servers that are sending out mail. It’s easy to lock them out with a bad SPF record.
Use a hard fail (for Hotmail’s behalf)
Your SPF record should end with either “~all” or “-all”. The “~all” is a soft fail. This means that servers not listed in your SPF record should be given extra scrutiny. The “-all” is a hard fail. This means that any server that tries to send an email from your domain that is not included on your SPF record will be rejected. Google recommends you use a soft fail (~all) to ensure deliverability, but in practice I found that specifying a hard fail was the only way to get an email into a Hotmail inbox. The hard fail communicates your confidence that your email system is secure. Most spam filters like that.
Submit your SPF record to Hotmail
You need to submit your SPF record to Hotmail to be included in their Sender ID program. Please note that Hotmail caches their records daily. This means if you change something you will need to resubmit your record in order to have your changes take effect immediately.
Subscribe to feedback loops
Feedback loops provide a way for ISP’s to let email senders know when people are clicking the “report spam” button. Google actively subscribes to these feedback loops so they can stop people from sending spam from their mail servers. Google allows you to be informed about these complaints as well. This allows you to quickly remove the complainers from your mailing list. You can get a copy of these complaints by creating email lists for email@example.com and firstname.lastname@example.org
Make sure you include a return-path in your email header
Sender ID checks are performed against the purported responsible address (PRA). SPF checks are performed against the return-path (or bounce address). This means you need to make sure you are sending the correct return-path in your email header and not something generic like “noreply@localhost”.
Make sure you are sending quality emails
There are a lot of things you can do to the emails themselves to increase your chances of getting past spam filters. There are a couple “no-brainers”, like making sure you include an unsubscribe link and use valid HTML. There are also a few not-so-obvious things you can do like adding your physical mailing address to the footer of each email. It’s worth taking some time to research what spam filters care about so you can modify your emails accordingly.
- Official site for Sender Policy Framework
- Learn more about Sender ID from Microsoft
- Microsoft’s wizard for creating Sender ID records
- Information about the CAN-SPAM Act
- Hotmail delivery tips for Sender ID and SPF
- Whitepapers on deliverability from Return Path
Please chip in your thoughts / questions. Good luck!