Back to blog
Threat Intel
Phishing Forensics

The Zero-Downtime ESP Migration: Your DKIM Cutover and Cleanup Playbook

A botched DKIM key rotation during an ESP migration guarantees deliverability problems; here's how to execute it without dropping a single email.

MailSleuth Research
Email Security Team
August 2, 20267 min read
Illustration of an old stone bridge being replaced by a new metal one, symbolizing a safe technology migration without d

The cutover window opens. You flip the switch, pointing your application's mailer from the old Email Sending Provider to the new one. An hour later, customer support tickets start rolling in: 'Did you send the password reset? I'm not seeing it.' Your marketing lead messages you on Slack: 'The campaign went out, but open rates are in the floor.' This isn't a hypothetical; it's the entirely predictable outcome of a bungled email authentication handoff.

Migrating from one ESP to another—say, from SendGrid to Postmark or AWS SES to Mailgun—is a common operational task. It's also incredibly easy to get wrong. The riskiest part isn't the API integration or the template migration. It's the cryptographic identity switcheroo managed by DKIM, and by extension, DMARC.

Get it wrong, and your domain's reputation takes a direct hit. Legitimate mail lands in spam or gets dropped entirely by receivers enforcing a strict DMARC policy. Get it right, and your users and customers won't notice a thing. This is how you get it right.

Phase 1: Stage the New Keys Before a Single Email Flies

Never, ever 'rip and replace' DKIM keys. The core principle of a zero-downtime migration is coexistence. You will have both the old and new ESP's DKIM keys published in your DNS simultaneously. This is perfectly valid and is precisely what the `s=` tag (the selector) in a DKIM signature was designed for, as specified in RFC 6376.

Provisioning the New Selector

Your new ESP will provide you with a DKIM public key to publish as a TXT record in your domain's DNS. It will have a unique selector. For instance, if your old ESP used `s1._domainkey.example.com`, your new one might provide a record for `mg._domainkey.example.com`. These selectors allow a receiving mail server to fetch the correct public key to verify a signature. Since they don't conflict, you can—and must—publish the new record while the old one is still active.

Publish this new TXT record immediately. Don't wait for migration day. DNS propagation isn't instantaneous, and some caching resolvers can hang on to old (or non-existent) records for far longer than the TTL suggests. Give it at least 24-48 hours to be globally visible before you even think about using it.

Pre-flight Verification

Once you've published the key, verify it. Don't trust the green checkmark in your ESP's dashboard. Get on a terminal and check it yourself. Use `dig` to confirm the record resolves correctly from a public DNS server like Google's or Cloudflare's.

dig TXT mg._domainkey.example.com @8.8.8.8

The output should show the exact `v=DKIM1; k=rsa; p=...` string your new provider gave you. A common failure mode is a copy-paste error where the long key string is broken up into multiple quoted strings in the DNS provider's UI, which can corrupt the record. Verifying with an external tool confirms that what you published is what the world's mail servers will see. A `permerror` verdict on a live mail flow due to a DNS typo is an unforced error.

Phase 2: Execute the Cutover and Read the Headers

With the new key provisioned and verified, the actual cutover becomes a low-drama event. You've already done the hard part. Now, you just re-route the mail flow.

Whether it's changing an environment variable in your application, updating an SMTP server address, or flipping a switch in a CDP, make the change that directs mail to the new ESP. Immediately after, send a test email from the system to a mailbox you control—preferably one hosted by a major provider like Google or Microsoft, as their headers are rich with diagnostic information.

Don't just check if you received it. Open the raw message source and find the `Authentication-Results` header. This is the ground truth. It's the receiving server's official report card on your email's authentication status.

Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (sender IP is ...) smtp.mailfrom=bounce@example.com; dkim=pass header.s=mg header.d=example.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=example.com

You are looking for two things here. First, `dkim=pass`. This confirms the signature is cryptographically valid. Second, `header.s=mg` (or your new selector). This confirms the email was signed with the new key. If you see `dkim=fail` or a `permerror`, something is wrong. A `fail` could mean the body was altered in transit—some forwarders or MTAs rewrite content, breaking the body hash. A `permerror` points back to a DNS problem with the public key record. This is your cue to enact the rollback plan.

Phase 3: Use DMARC to Verify the Old Key's Retirement

The new key is working. The migration is done, right? Wrong. The job isn't finished until you are 100% certain that no legitimate email is being signed with the old ESP's DKIM key.

This isn't something you can find by checking your main application's code. You might have a forgotten microservice, a developer's cron job, a WordPress plugin, or even a third-party SaaS tool that was configured to relay through your old provider years ago. These forgotten senders are the landmines of an ESP migration.

Your DMARC aggregate reports are the only way to find them. As defined in RFC 7489, these XML reports sent by receivers give you a census of all emails seen using your domain, including their SPF/DKIM authentication results and the DKIM selectors used. Over the next 7-14 days following the cutover, monitor these reports closely. You should see all legitimate traffic shift from showing the old selector (`s1`) to the new one (`mg`).

If you see any legitimate volume still being signed with `s1`, your job is to play detective. The source IP address in the DMARC report is your starting point. Hunt down that forgotten sender and update its configuration. Do not proceed to the next phase until the DMARC data shows zero legitimate traffic using the old key for at least a week.

Phase 4: Decommissioning With Confidence

Deleting the Old DNS Record

Only when your DMARC reports have been clean for a solid period—I recommend two weeks to be safe—can you finally decommission the old assets. The primary task is to delete the old DKIM TXT record from your DNS (e.g., `s1._domainkey.example.com`).

Deleting it prematurely is dangerous. If even one server is still sending mail signed with that old key, any receiver trying to verify it will query DNS, find nothing, and return a `dkim=permerror`. This permanent error will cause a DMARC failure for that message. If your DMARC policy is `p=reject`, that legitimate (but misconfigured) email is now silently dropped. This is why the monitoring phase is not optional.

Building Your Rollback Plan

What if the cutover test fails? What if you see `dkim=fail` and can't debug it under pressure? The rollback plan should be trivial because you've followed this process. Since the old ESP's DKIM key is still published and valid, a rollback is simply a matter of reverting the change you made in Phase 2. Point your application back to the old provider's API or SMTP endpoint.

This safety net exists only because you embraced key coexistence. A 'big bang' migration where you delete the old key and add the new one simultaneously gives you no room for error and guarantees an outage if something goes wrong. This methodical approach turns a high-risk change into a series of verifiable, reversible steps.

Conclusion

An ESP migration is a deliverability minefield, but it doesn't have to be. By treating DKIM keys as cryptographic assets with a distinct lifecycle—provision, verify, monitor, and decommission—you can de-risk the entire process. The key is to let DMARC data guide your final step. Don't guess when it's safe to remove the old key; wait for the reports to prove it to you.

This isn't just about technical correctness. It's about protecting revenue, maintaining customer trust, and ensuring your team's hard work actually reaches its intended audience. A successful migration is one that nobody notices. Parsing dense XML DMARC reports can be tedious, which is why platforms like MailSleuth.AI exist to turn that data into actionable intelligence, making it trivial to spot when an old selector has finally disappeared.

The takeaway

An ESP migration is a deliverability minefield, but it doesn't have to be. By treating DKIM keys as cryptographic assets with a distinct lifecycle—provision, verify, monitor, and decommission—you can de-risk the entire process. The key is to let DMARC data guide your final step. Don't guess when it's safe to remove the old key; wait for the reports to prove it to you.

This isn't just about technical correctness. It's about protecting revenue, maintaining customer trust, and ensuring your team's hard work actually reaches its intended audience. A successful migration is one that nobody notices. Parsing dense XML DMARC reports can be tedious, which is why platforms like MailSleuth.AI exist to turn that data into actionable intelligence, making it trivial to spot when an old selector has finally disappeared.

#dkim#dmarc#esp-migration#email-deliverability#email-security
MailSleuth Research
Email Security Team

We dissect phishing campaigns and email infrastructure so you don't have to.