<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prabhu Ganesan</title>
    <description>The latest articles on DEV Community by Prabhu Ganesan (@prabhu_ganesan).</description>
    <link>https://dev.to/prabhu_ganesan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4250943%2F72cb51d0-6a78-4056-bebb-48ae97eb5d69.jpg</url>
      <title>DEV Community: Prabhu Ganesan</title>
      <link>https://dev.to/prabhu_ganesan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prabhu_ganesan"/>
    <language>en</language>
    <item>
      <title>How to Set Up SPF, DKIM and DMARC for a New Domain (Step by Step)</title>
      <dc:creator>Prabhu Ganesan</dc:creator>
      <pubDate>Wed, 18 Nov 2026 06:19:39 +0000</pubDate>
      <link>https://dev.to/namelume/how-to-set-up-spf-dkim-and-dmarc-for-a-new-domain-step-by-step-24c3</link>
      <guid>https://dev.to/namelume/how-to-set-up-spf-dkim-and-dmarc-for-a-new-domain-step-by-step-24c3</guid>
      <description>&lt;p&gt;You've bought a domain, set up &lt;code&gt;hello@yourdomain.com&lt;/code&gt;, and sent your first email. Then it lands in spam. Or worse, it never arrives.&lt;/p&gt;

&lt;p&gt;Most of the time the fix is three DNS records: &lt;strong&gt;SPF&lt;/strong&gt;, &lt;strong&gt;DKIM&lt;/strong&gt; and &lt;strong&gt;DMARC&lt;/strong&gt;. I set these up for my own startup's domain recently, made a couple of mistakes along the way, and wrote down what actually worked. This guide walks through each record in the order you should add them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What these three records do (in one minute)
&lt;/h2&gt;

&lt;p&gt;Think of an email like a letter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SPF&lt;/strong&gt; is a list of post offices allowed to send letters for your domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DKIM&lt;/strong&gt; is a wax seal on each letter that proves nobody changed it on the way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DMARC&lt;/strong&gt; tells the receiving post office what to do if a letter fails those checks, and sends you reports about it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gmail and Yahoo now expect bulk senders to have all three, and even small senders get better delivery with them. Without them, anyone can pretend to send email as your domain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you start
&lt;/h2&gt;

&lt;p&gt;You need two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Access to your domain's DNS settings.&lt;/strong&gt; This is wherever your domain's nameservers point: your registrar, your hosting provider, Cloudflare, Vercel, and so on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A list of every service that sends email as your domain.&lt;/strong&gt; This is the step people skip. Usually it's at least two:

&lt;ul&gt;
&lt;li&gt;Your &lt;strong&gt;mailbox provider&lt;/strong&gt; (Google Workspace, Zoho Mail, Microsoft 365) for normal emails.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;app or marketing sender&lt;/strong&gt; for order confirmations, password resets or newsletters.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Write the list down. Every service on it needs to appear in SPF and needs its own DKIM key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: Check your MX records first
&lt;/h2&gt;

&lt;p&gt;MX records tell the world where to &lt;em&gt;deliver&lt;/em&gt; email for your domain. Your mailbox provider gives you these when you set up your inbox. They look like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Host&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Priority&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;MX&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;mx.yourmailprovider.com&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MX&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;mx2.yourmailprovider.com&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;A mistake I hit:&lt;/strong&gt; my DNS records were being added through an API, and the priority field had a different name than I expected. The records saved without errors but didn't work. If email isn't arriving, look up your MX records with a public checker before blaming anything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Add SPF
&lt;/h2&gt;

&lt;p&gt;SPF is a single &lt;strong&gt;TXT record&lt;/strong&gt; on your root domain (&lt;code&gt;@&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;v=spf1 include:_spf.yourmailprovider.com include:sendingservice.com ~all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How to read it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;v=spf1&lt;/code&gt; means "this is an SPF record".&lt;/li&gt;
&lt;li&gt;Each &lt;code&gt;include:&lt;/code&gt; adds one service that's allowed to send for you. Your providers tell you exactly what to put here.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;~all&lt;/code&gt; means "anything else is suspicious" (a soft fail). Once you're confident everything is listed, you can switch to &lt;code&gt;-all&lt;/code&gt; (hard fail).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rules that trip people up:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only one SPF record per domain.&lt;/strong&gt; Two separate &lt;code&gt;v=spf1&lt;/code&gt; records break SPF completely. If you add a new sender, edit the existing record and add another &lt;code&gt;include:&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maximum 10 DNS lookups.&lt;/strong&gt; Each &lt;code&gt;include:&lt;/code&gt; costs at least one lookup, and some include others inside them. Too many senders and SPF fails. If you're close, remove services you no longer use.&lt;/li&gt;
&lt;li&gt;It goes on &lt;code&gt;@&lt;/code&gt; (the root), not on a subdomain, unless you send from that subdomain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Add DKIM
&lt;/h2&gt;

&lt;p&gt;DKIM is a cryptographic signature added to every email. Each sending service generates its own key pair. You publish the public key in DNS, and the service signs your emails with the private key.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In each sending service, find the DKIM or "domain authentication" setting.&lt;/li&gt;
&lt;li&gt;It gives you a record to add. It's usually a &lt;strong&gt;TXT&lt;/strong&gt; record like this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host:  selector1._domainkey
Type:  TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some services give you a &lt;strong&gt;CNAME&lt;/strong&gt; instead, pointing to a key they host. Use exactly what they give you.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;selector1&lt;/code&gt; part is the "selector". Every service uses a different one, so several DKIM records can live side by side without clashing.&lt;/li&gt;
&lt;li&gt;Go back to the service and click &lt;strong&gt;Verify&lt;/strong&gt;, then make sure signing is switched &lt;strong&gt;on&lt;/strong&gt;. Some services publish the key but don't sign until you enable it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Repeat this for &lt;strong&gt;every&lt;/strong&gt; service on your list. One DKIM record for your inbox provider doesn't cover your app's transactional emails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; long DKIM keys sometimes get split or truncated by DNS panels. If verification fails, check that the whole key was pasted as one value, with no extra spaces or quotes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Add DMARC
&lt;/h2&gt;

&lt;p&gt;DMARC is a &lt;strong&gt;TXT record&lt;/strong&gt; on the &lt;code&gt;_dmarc&lt;/code&gt; host. Start in monitoring mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host:  _dmarc
Type:  TXT
Value: v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;p=none&lt;/code&gt; means "don't block anything yet, just report". Always start here.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rua=&lt;/code&gt; is where receiving servers send daily summary reports. Use an address you actually check, or a free DMARC report tool that reads them for you.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DMARC passes only when SPF &lt;strong&gt;or&lt;/strong&gt; DKIM passes &lt;strong&gt;and&lt;/strong&gt; the domain they check &lt;em&gt;matches&lt;/em&gt; the domain in the visible "From" address. This "alignment" rule catches a common mistake.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The mistake I almost shipped:&lt;/strong&gt; my app's email code had a default "From" address on a &lt;em&gt;different&lt;/em&gt; domain than the one I'd authenticated. SPF and DKIM were set up perfectly for the right domain, but the emails claimed to come from another one, so they'd never align. Check the actual From address your app uses in production, not just your DNS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tightening DMARC later
&lt;/h3&gt;

&lt;p&gt;After a week or two of clean reports showing all your real senders passing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Move to &lt;code&gt;p=quarantine&lt;/code&gt; (failures go to spam).&lt;/li&gt;
&lt;li&gt;Later, move to &lt;code&gt;p=reject&lt;/code&gt; (failures are refused).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Don't jump straight to &lt;code&gt;reject&lt;/code&gt; on a new domain. If you forgot a sender, its emails will vanish.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Test it
&lt;/h2&gt;

&lt;p&gt;DNS changes can take from a few minutes to a few hours to spread.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Send an email from &lt;strong&gt;each&lt;/strong&gt; sending service to a Gmail address.&lt;/li&gt;
&lt;li&gt;In Gmail, open the email, click the three dots, then &lt;strong&gt;Show original&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Look for three lines near the top:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SPF:   PASS
DKIM:  'PASS' with domain yourdomain.com
DMARC: 'PASS'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If one fails, the message headers usually say why: a missing &lt;code&gt;include:&lt;/code&gt;, a DKIM selector that isn't published, or a From domain that doesn't align.&lt;/p&gt;

&lt;p&gt;You can also run your domain through any public SPF, DKIM or DMARC checker to catch syntax errors before sending.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] MX records point to your mailbox provider&lt;/li&gt;
&lt;li&gt;[ ] One SPF record on &lt;code&gt;@&lt;/code&gt;, with an &lt;code&gt;include:&lt;/code&gt; for every sender, under 10 lookups&lt;/li&gt;
&lt;li&gt;[ ] A DKIM record for &lt;strong&gt;each&lt;/strong&gt; sending service, verified and signing switched on&lt;/li&gt;
&lt;li&gt;[ ] A DMARC record on &lt;code&gt;_dmarc&lt;/code&gt;, starting with &lt;code&gt;p=none&lt;/code&gt; and a report address&lt;/li&gt;
&lt;li&gt;[ ] Your app's real "From" address uses the same domain you authenticated&lt;/li&gt;
&lt;li&gt;[ ] Test emails from every service show SPF, DKIM and DMARC as PASS&lt;/li&gt;
&lt;li&gt;[ ] After 1–2 weeks of clean reports, tighten DMARC to &lt;code&gt;quarantine&lt;/code&gt;, then &lt;code&gt;reject&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;These three records take maybe 30 minutes to set up, and they're the difference between "your email is in their inbox" and "your email is in spam, or someone is sending phishing emails as you".&lt;/p&gt;

&lt;p&gt;I'm building &lt;a href="https://namelume.in" rel="noopener noreferrer"&gt;Namelume&lt;/a&gt;, a domain registration service for small businesses in India, and email setup is one of the first things new domain owners get stuck on. If you hit a problem not covered here, leave a comment and I'll try to help.&lt;/p&gt;

</description>
      <category>dns</category>
      <category>email</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
