sam rowe

A fast intro to Sender Policy Framework

Sender Policy Framework controls which IP addresses can send emails from your domain name. It’s not strictly required, but without it you will find a lot of services either block your emails or put them in “Spam”.

To configure SPF for your domain, create a DNS TXT record that looks like this:

v=spf1 ip4:192.0.2.0/24 include:otherdomain.com a -all

An SPF policy starts with the version: v=spf1. Then it lists all of the mechanisms which are allowed to send email (or not) from that domain:

Qualifiers

Why is there a dash at the start of -all in the policy above?

It’s a qualifier which tells the email receiver to reject emails from that source. Having just all (or +all) in our SPF policy means “accept emails from all other sources” whereas -all means “reject emails from all other sources”.

You can add a qualifier to any of the SPF mechanisms, for example -ip4:... or ~mx.

SPF qualifiers
QualifierResultNotes
+PASSAccept emails from this source. The default.
?NEUTRALTreat the source as if there was no SPF policy set.
~SOFTFAILAccept emails from this source but “tag” them (often this means putting them in the spam folder); useful for debugging.
-FAILReject emails from this source.

PASS is the default if there’s no qualifier, so mx and +mx mean the exact same thing.

? seems a bit pointless and + is optional, so in reality you’ll generally only use ~ and -. Use SOFTFAIL when you’re setting up and testing your SPF policy, and FAIL once you’re confident you’ve got it right.

When testing keep in mind that there is variation in how email hosts treat the different qualifiers. For example, Outlook.com puts SOFTFAIL emails in spam, but Gmail appends “via actualsender.com” to the “From” field instead. I imagine it also depends on the reputation of the sender.

Happy emailing! đź‘‹

See also

Last updated on