SPF Records
If you're not familiar with the SPF syntax, the place to go is http://openspf.org.
Google recommends anyone using Google Accounts for their email to use the following SPF record:
v=spf1 include:aspmx.googlemail.com ∼all
The include mechanism includes the SPF record of the domain specified if it exists. Don't be tempted to simply include any domain, such as google.com for instance. It needs to be specifically the domain containing an SPF record that allows the mail servers used by Google to send email for their customers. If google.com has an SPF record, it may be only for emails sent from @google.com email addresses, and including it in your SPF may cause it to always return failures!
Looking up the DNS record of aspmx.googlemail.com we find the following:
host: aspmx.googlemail.com type: TXT txt: v=spf1 redirect=_spf.google.com class: IN ttl: 7200
The redirect mechanism does the obvious, it redirects the lookup to the domain specified. So looking up _spf.google.com we find:
host: _spf.google.com type: TXT txt: v=spf1 ip4:216.239.32.0/19 ip4:64.233.160.0/19 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:209.85.128.0/17 ip4:66.102.0.0/20 ip4:74.125.0.0/16 ?all class: IN ttl: 300
The ip4 mechanism allows you to specify specific IP addresses or blocks of IP ranges using the CIDR syntax. How this SPF string is interpreted is it allows all of the IP addresses specified to send mail, and ?all means this record is neutral about any other IP addresses that might send mail for this domain. When an SPF record is published to be used as an include in other SPF records, using ?all apparently allows the parent SPF to allow more mail servers and to specify how to handle any server not specifically allowed, using either ∼all for a softfail when no match occurs (meaning look more carefully please) or -all for a hardfail (which means don't allow, period).
I learned a lot simply by looking at what Google does, and wound up recommending to HostMySite that they implement a similar approach. I hope they can implement my recommendation, which includes an internal policy to make sure their SPF record is updated whenever their outbound mail servers change, because simply being able to include:spf.safesecureweb.com in my SPF record will allow me to do it once and forget it. Otherwise I need to figure out a way to remain current with the IP's they allocate to be used for their mail servers, which would be a pain.
So the proposed SPF record I wound up with for this client, provided HostMySite follows my recommendation, is:
"v=spf1 ip4:212.147.58.12 a include:spf.safesecureweb.com include:aspmx.googlemail.com ∼all"
which will be interpreted as "allow the exchange server at 212.147.58.12 and include any allowed mail servers at spf.safesecureweb.com and aspmx.googlemail.com, and if another mail server tries to send email for this domain, softfail it and give it a closer look."
At openspf.org you'll find a link to a testing tool that allows you to test your SPF strings. It's very handy. Once your SPF string passes validation using this testing tool to simulate sending email from various IP's possible, THEN you can modify your DNS record to include an SPF record with more confidence that what you have come up with will work well.
Update: HostMySite has adopted the suggestion I put forward to them. Their SPF record is at spf.safesecureweb.com and contains their ranges of allocated IPs. They've told me they will keep it updated going forward. Spread the word!


[Just a couple of copy edits: the link to Google's spf help page seems to be wrong, and in the last para: "Once your SPF sting"...]
Let us know if HMS adopt your suggestion. Cheers, Julian.
Here on my computer the spf record your mention does not show correct.
The sign just before all , becomes a box instead of a "tilde". Maybe a little confusing, could be a problem i someone copy paste it.
Best regards.
How does a receiving mail server query these other spf records if it cannot resolve to them?
These include will work because aspmx.googlemail.com does not need to have an A record, but a TXT record instead.
if you do:
$ dig aspmx.googlemail.com TXT
you will get:
aspmx.googlemail.com. 7200 IN TXT "v=spf1 redirect=_spf.google.com"
Even in the case that aspmx.google.com dies not have an IP address (A-Record)
"v=spf1 ip4:xxx.xxx.xx.xx a include:aspmx.googlemail.com
... so that both the server and google are authorized senders?
And is the IP address really needed if you have the "a" there, and if the IP address is already listed as an A entry for that domain?
Thanks for writing such a clear post.
"v=spf1 ip4:xxx.xxx.xx.xx a include:aspmx.googlemail.com ~all"
and, specifically, I'm wondering if this, with the IP address but with the "a" might not be just as effective for people who want to authorize email from both their server and Google Apps:
"v=spf1 a include:aspmx.googlemail.com ~all"