How to create and add an SPF record for email authentication

Hackers love to forge malicious email on domains they do not personal to perform their evil schemes. An effective way to combat again in opposition to spammers is to promote which email servers, IP addresses and domains are licensed to ship mail on behalf of that area. Implementing the Sender Policy Framework protocol by creating an SPF record is an effective way to begin combating again.

This tutorial introduces key SPF ideas, together with SPF record syntax, and exhibits how to create an SPF record. Examples of SPF information are additionally included, in addition to steerage on how to add an SPF record to DNS by creating a brand new DNS TXT record.

What is SPF and how does it work?

SPF is one among three email authentication protocols that work collectively to defend in opposition to email spoofing, spam and phishing by giving email senders a set of instruments to accomplish the next:

  • determine the hostname, domain or IP address for servers licensed to ship mail for a site, utilizing SPF information;
  • authenticate digitally signed messages, utilizing public keys saved in DomainKeys Identified Mail (DKIM) information; and
  • notify email-receiving servers how to course of email from a site when it fails to authenticate, utilizing Domain-based Message Authentication, Reporting and Conformance (DMARC).

These email authentication protocols all use DNS information to retailer details about email providers offered by the area holder:

  • DKIM information embody a public key used to authenticate email that has been digitally signed utilizing the protocol.
  • DMARC information embody directions for email-receiving organizations to point out what steps they need to take when an unauthenticated email is obtained.
  • SPF records embody steerage on how to determine legitimate IP addresses, domains and subdomains licensed to ship email on behalf of the particular area within the email header.

SPF and its sibling protocols all rely on utilizing DNS to distribute the knowledge email receivers want so as to authenticate incoming email with out affecting email deliverability. These protocols work by having the email-sending group create DNS TXT information to publish guidelines for authenticating the email originated from the area homeowners. Knowing how to add a DNS TXT record is a big a part of the method of making any SPF, DKIM or DMARC record.

Email spoofing happens when malicious actors try to ship email for a site they do not personal.

All organizations that ship email for their very own area can profit from creating information in DNS that recipients can use for email validation. The course of for creating DNS information varies relying on whether or not mail is shipped by an email service supplier, a internet hosting supplier, an ISP or another third-party mail server that sends email on behalf of an group’s area. The course of for creating the brand new SPF record additionally could also be sophisticated relying on the area proprietor’s email infrastructure.

SPF TXT information include IP addresses and domains for mail servers which can be licensed to ship mail for the related area. Email-receiving servers do an SPF verify to decide whether or not an email originated from an licensed IP deal with, area or subdomain and to use that info to resolve whether or not to ship the email.

SPF record syntax

SPF syntax, as outlined in Internet Engineering Task Force RFC 7208, specifies three elements in SPF information: mechanisms, qualifiers and modifiers.

Mechanisms are the strategies SPF can use to confirm {that a} specified area is permitted to ship email. A mechanism is alleged to match if some recognized situation is met. Depending on the mechanism, a match signifies that the message may be validated. SPF mechanisms embody the next:

  • v is the model of SPF used within the record. This mechanism is required and should seem at first of the record. The solely legitimate worth for this mechanism is v=spf1 — for SPF model 1. This mechanism ought to match all messages.
  • ALL is the mechanism to choose all inbound messages. While not required, the advice is to embody this mechanism in all SPF information — because the final mechanism — because it gives a default mechanism to match any incoming messages that are not in any other case explicitly authenticated.
  • A, or deal with, is the mechanism for figuring out the deal with being utilized by licensed servers. “A” refers to the DNS A or deal with record kind. This mechanism specifies that every one IP deal with information for the required area needs to be examined. If the supply IP deal with of the mail server is present in any of the deal with information, the mechanism matches.
  • IP4 refers to the IPv4 community deal with. This mechanism may be specified as a community vary when the deal with is supplied with the prefix size to specify subnetting or as a single IPv4 deal with when specified with out the prefix size.
  • IP6 refers to the IPv6 network address, which may be specified as a community vary when the deal with is supplied with the prefix size to specify subnetting or when specified with out the prefix size to reference a number at a particular IPv6 deal with.
  • MX refers to the DNS MX or mail change record kind. This mechanism is used to specify a site or subdomain, and the receiving mail server processes this mechanism by querying for all of the deal with information for that area or subdomain. This mechanism matches when the MX information include the identical area as used to ship the message.
  • PTR refers to the DNS PTR or pointer record kind. The mechanism is taken into account gradual and unreliable, and it can also stress DNS as a result of it requires a comparatively excessive variety of DNS queries. While it’s nonetheless included within the SPF specification, it’s endorsed not to use it for these causes.
  • EXISTS specifies a site, and the receiving mail server queries DNS for deal with information for that area. With any consequence — if a number of deal with information are discovered — this mechanism matches, it doesn’t matter what the deal with is. This mechanism is used for particular functions, together with reverse IP lookups and organising exceptions for particular customers.
  • INCLUDE is a mechanism for recursive matching. This mechanism is specified with a site, which is queried for an SPF record. If the area doesn’t have an SPF record, the mechanism returns fail. If that area does have an SPF record, the receiving server processes that SPF record, and if it matches, the mechanism returns go.

Qualifiers are prefixes that may optionally be added to mechanisms to specify what occurs when a receiving email server matches the mechanism:

  • +, or go, signifies that matching this mechanism means the email passes authentication.
  • , or arduous fail, signifies that matching this mechanism means the email fails authentication.
  • ~, or comfortable fail, signifies that matching this mechanism in all probability fails authentication and needs to be handled as suspicious.
  • ?, or impartial, signifies that matching this mechanism means the SPF record doesn’t go or fail the message and has no info out there to validate the sender. Mail that matches this mechanism is accepted.

For instance, the mechanism listed as -all would imply that every one mail from the area needs to be rejected. The mechanism matches for each incoming message from the area, and the qualifier — arduous fail — signifies that these matches imply the message needs to be thought-about unauthorized.

Modifiers are an extra, non-obligatory part of SPF information that present extra info however do not change how messages are authenticated. The two legitimate modifiers outlined for SPF are the next:

  1. Redirect modifiers embody a site that needs to be queried for the legitimate SPF for the incoming message. When an email-receiving server sees this modifier within the SPF record for a message, the server should do a DNS lookup for the area within the redirect modifier.
  2. Exp modifiers embody a site that needs to be queried to obtain an clarification for the explanation a server rejects a message.

SPF information are typically text-only, and elements are separated by areas. The default qualifier is go, so SPF information may be terse. Mechanisms with parameters like domains or IP addresses are entered within the SPF record after the mechanism identify and a colon, for instance:

v=spf1 -all

Note: The A or deal with mechanism used right here,, lists the area to be queried for addresses to match with the deal with of the sending email server. More examples of SPF information comply with.

Examples of SPF information

A easy kind of SPF record seems like this:

v=spf1 -all

In this case, the SPF record’s message is: There is not any licensed supply for email from this area. This is the really useful SPF record for nonsending domains; it actually means all email needs to be rejected. Two mechanisms are used, the v=spf1 model and the all mechanism, which, by default, all the time permits any domains not in any other case dominated out by earlier guidelines. ALL is just used on the finish of the SPF record for that cause. In follow, the protocol ignores any mechanisms that comply with ALL in an SPF record.

A extra helpful instance seems like this:

v=spf1 -all

In this case, the primary mechanism is mx, which, by default, permits mail from the DNS MX record for the area The hyphen qualifier used with the catchall -all mechanism means any mail that fails to match the DNS MX record for the sending area needs to be processed as failed.

Another frequent instance that depends on DNS to allow the area proprietor to reference a special area seems like this:

v=spf1 -all

In this case, the embody mechanism is used to add the SPF record for customers of customized domains in Microsoft Office 365 (

Domain homeowners utilizing Google Workspace for their email would possibly use a record that appears one thing like this:


Taking this record one line at a time, mechanisms are defined within the following desk:

SPF record line Notes


SPF model 1


Email is permitted to be despatched from an email server within the IP deal with vary of by

Match recursively with the SPF record saved within the DNS TXT record named This is the place Google shops the SPF record for its Google Workspace clients.


Match recursively with the SPF record saved within the DNS TXT record named mailservice.instance.internet. This stands for a reputation that references an SPF record printed by a mail service supplier.


Everything else that does not in any other case match prior mechanisms needs to be handled as a comfortable fail and despatched to a unsolicited mail or spam folder.

In this instance, the area proprietor authorizes email despatched from servers situated by itself IP community: refers to the community deal with of and any host with an IP deal with on that community. Email originating from some other IP deal with vary have to be recursively matched by each Google’s personal SPF record ( and the SPF record related to the area proprietor’s email service supplier (mailservice.instance.internet).

Incoming email that fails to match on any of those mechanisms — IPv4 deal with, Google Workspace SPF record and the SPF record offered by the email service supplier — needs to be thought-about questionable and delivered to the recipient’s spam folder.

It’s greatest to use these examples of SPF information as beginning factors to develop a deployment technique that features coordination with email service suppliers, area service suppliers, area directors and employees throughout the group who administer email techniques.

How to add an SPF record

Once composed, the SPF record have to be printed as a DNS TXT record. This will not be an motion to be taken evenly — including a DNS record impacts how the area is utilized by the whole web.

DNS TXT information are generally added utilizing the DNS service supplier’s net portal or utility. The course of could also be so simple as choosing the Add Record possibility from a pull-down menu and then getting into the elements of the record.

Domain administration for enterprises and different massive organizations could also be administered by IT and networking professionals utilizing Microsoft’s Active Directory service to add DNS TXT information to the enterprise DNS servers, however the modifications should nonetheless be propagated into basic distribution over the web by the area’s DNS service supplier.

Related Posts