Understanding SPF and CNAME Records for Emails

adil
4 min readMar 12, 2024

Sending email from a subdomain can be difficult. This can be more difficult if there is a CNAME on the subdomain.

Photo by Brett Jordan on Unsplash

I created a domain: blog.adililhan.com

I will send an email to my Gmail and Outlook accounts from info@blog.adililhan.com

Scenario 1: Primary Domain has SPF. No SPF on Subdomain

SPF Tool:

Outlook:

Gmail:

Scenario 2: No SPF in the primary domain. Subdomain Has SPF

Outlook:

Gmail:

SPF Tool:

Scenario 3: No SPF in the primary domain. No SPF in the subdomain

SPF Tool

Outlook:

Gmail:

Scenario 4: Block all domains in the primary domain. The subdomain has the correct SPF Record

SPF Tool:

Outlook:

Gmail:

Scenario 5: Block all domains in the primary domain. No SPF in the subdomain

SPF Tool:

Outlook:

Gmail:

We’ve made sure that you need an SPF record on the subdomain so that you can send emails from it.

CNAME and SPF Record

A CNAME record can’t coexist with any other DNS type.

I will attempt to create a CNAME record for blog.adililhan.com:

blog.adililhan.com -> CNAME -> anotherblog.adililhan.com

The DNS editor I use doesn’t allow me to add the CNAME record:

Because I already have a DNS record for blog.adililhan.com :

I will remove those DNS records and try to add a CNAME record.

I managed to add the CNAME record:

I purposely created a CNAME chain:

blog.adililhan.com-> CNAME anotherblog.adililhan.com-> CNAME blog123.adililhan.com

SPF Tool:

If your domain has a CNAME, you need to add your SPF records to the last domain in the chain .The last domain is blog123.adililhan.com

SPF Tool:

Outlook:

Gmail:

Return-Path and SPF

I sent emails using Mailgun. I cannot modify the Return-Path in Mailgun. It is important to remember that the domain in the Return-Path field—rather than the domain in the From field—will be used for the SPF check.

From: info@blog.adililhan.com
Return-Path: admin@blog.xyz.com

blog.xyz.com must have the correct SPF records.

--

--