What are SPF records, and how do I configure them?

Better Stack Team
Updated on November 23, 2023

Sender Policy Framework (SPF) is an email authentication protocol used to prevent email spoofing, a technique used by spammers and cybercriminals to send emails with forged sender addresses. SPF allows domain owners to specify which mail servers are authorized to send emails on behalf of their domain.

Configuring SPF involves adding a specific TXT record to the Domain Name System (DNS) for your domain. This TXT record contains information about the authorized mail servers for your domain. Here's a general outline of how to configure SPF records:

  1. Understand your domain's existing SPF status: Before creating an SPF record, check if your domain already has one. You can use various online tools or query the DNS directly to check existing SPF records.
  2. Create or modify an SPF record: You need to create a TXT record in your DNS settings. The TXT record will contain the SPF information for your domain. Here's an example of an SPF record: v=spf1 include:_spf.example.com ~all
    In this example:
  3. v=spf1 specifies the SPF version.
  4. include:_spf.example.com includes SPF information from another domain (_spf.example.com). This can include IP addresses or other SPF mechanisms.
  5. ~all signifies a soft fail. It means that emails that don't match the specified criteria should be treated with suspicion but not rejected outright.

  6. Determine your SPF mechanism: The SPF record includes different mechanisms to define which servers are authorized to send emails on behalf of your domain. Common mechanisms include include, a, mx, ip4, and all. You can use one or a combination of these mechanisms in your SPF record.

  7. Set up the record in your DNS provider's settings: Access your domain's DNS settings through your DNS hosting provider and add or edit the TXT record. Each provider has its interface, so the exact steps might vary. Look for options related to DNS records and TXT records.

  8. Testing and validation: Once the record is configured, it's important to test it to ensure that it's set up correctly. You can use online SPF checking tools to verify the SPF record's syntax and if it's accurately reflecting the intended mail servers.

  9. Regularly update and maintain: It's crucial to keep your SPF record updated as your mail infrastructure changes. If you add or remove mail servers, update your SPF record accordingly.

Remember that incorrectly configured SPF records can lead to email delivery issues, so it's essential to follow the syntax rules and review your record after any changes.

If you're uncertain about how to create or modify SPF records, it's recommended to consult with your DNS hosting provider or a knowledgeable IT professional for assistance.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.


or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github