DKIM Setup Guide: How to Sign Your Email and Prove It Is Really From You
When a customer opens an email from your company, the receiving mail server asks a simple question: did this message really come from you, and was it changed along the way? DKIM, short for DomainKeys Identified Mail, lets you answer yes with cryptographic proof. Instead of relying only on the sending server's address, DKIM attaches a digital signature to every outgoing message. That signature is tied to your domain, so it travels with the message through forwarding and relaying and can be checked by any receiver, anywhere.
If you send newsletters, invoices, password resets, or order confirmations, DKIM is a practical step to protect your domain and improve inbox placement. This guide covers how signatures work, generating a strong key, publishing it in DNS, configuring signing, and testing and troubleshooting the result.
What DKIM Is and Why It Matters
DKIM is an email authentication standard that uses public-key cryptography. You keep a private key secret on your sending server, and you publish the matching public key in your domain's DNS records. When your server sends a message, it uses the private key to create a signature based on the contents of that message. The receiving server then looks up your public key in DNS and checks whether the signature is valid.
If the check passes, the receiver knows that someone with access to your private key authorised the message for your domain, and that the signed parts were not altered in transit. If it fails, or if there is no signature at all, the receiver has less reason to trust the message and may place it in spam or reject it, depending on its policies and on your DMARC record.
- Brand protection: DKIM makes it much harder for a third party to send convincing mail claiming to be from your domain without detection.
- Deliverability: Major mailbox providers use authentication as a trust signal, and signed mail is treated more predictably than unsigned mail.
- Accountability: Your reputation follows your domain, rather than only a shared IP address.
- Integrity: The signature covers selected headers and the body, so tampering after signing breaks verification.
How DKIM Signatures and Headers Work
Every signed message carries an extra header called DKIM-Signature. You will rarely see it in a normal mail client, but behind that header is a defined process that sender and receiver follow in mirror image.
What the sending server does
The signing software chooses which headers to include, such as From, To, Subject, and Date. It creates a hash, a short mathematical fingerprint, of those headers and a separate hash of the message body. Those hashes are combined and encrypted with your private key. The result becomes the signature in the DKIM-Signature header, along with labels telling the receiver which domain signed the message, which selector to use, which algorithm was used, and which headers were signed.
What the receiving server does
The receiver reads the signature header and notes the signing domain and selector. It queries DNS for a TXT record at an address built from those two values, and that record contains your public key. The receiver independently hashes the same headers and body, uses the public key to decrypt your signature, and compares the results. If they match, the signature is valid. If a single signed character changed in transit, the hashes will not match and the check will fail.
- d= identifies the signing domain responsible for the message.
- s= identifies the selector, which points to one specific key.
- h= lists the headers included in the signature.
- bh= is the hash of the message body.
- b= is the actual cryptographic signature.
- a= names the algorithm, most commonly rsa-sha256 today.
Before You Start: What You Need
Preparation saves back-and-forth later. Confirm that you can edit DNS for your sending domain, list every service that sends mail for it — a website form, billing system, help desk, CRM, and newsletter tool can all send as the same domain — and ensure you have access to the server or platform that will sign.
- Access to your DNS control panel or DNS provider's API.
- A list of every system that sends email for your domain.
- Access to the mail transfer agent or sending platform you will configure.
- Your existing SPF and DMARC records, so the new setup aligns with them.
If you run your own infrastructure on a dedicated SMTP email server, you control both the private key and the signing configuration directly. If you use a hosted service, it will usually generate the key for you and ask you to publish the DNS record it provides. The steps are the same; only the screens differ.
Step 1: Choose Your Signing Domain and Selector
The signing domain should normally be the same organisational domain that appears in your From address, or a subdomain of it that you control. Using a domain you do not control, or one that does not line up with your From address, creates alignment problems for DMARC and confuses receivers about who is responsible for the message.
Next, choose a selector: a short label identifying one particular key. Because the selector forms part of the DNS lookup address, you can keep several keys active at once, which is essential for safe rotation. Use descriptive names such as s1 or mail2026, and keep a record of which selector belongs to which service and when it is due for rotation.
Step 2: Generate a 2048-Bit Key Pair
Key length determines how hard the private key is to guess or crack. Older 1024-bit RSA keys are now considered too weak for long-term use, and some receivers treat them with suspicion. A 2048-bit RSA key is the widely recommended balance today: strong enough to be trusted, and compatible with DNS and receiving servers everywhere. Longer keys can create oversized DNS records and compatibility problems without a practical benefit for most senders.
On a server you control, key generation is usually done with a tool supplied with your signing software, or with a general tool such as OpenSSL. The process always produces the same two things: a private key file that stays on the server with strict permissions, readable only by the signing process, and a public key formatted for DNS. Some tools also generate the ready-made TXT record text for you, which reduces the chance of a copy-and-paste error.
- Generate the key for the exact domain and selector you chose.
- Store the private key outside any public web directory.
- Restrict permissions so only the mail service account can read it.
- Back up the key securely and note the date it enters service.
- Never share, email, or publish the private key anywhere.
Step 3: Publish the Public Key in DNS
Your public key lives in a TXT record at an address formed by the selector, followed by ._domainkey, followed by your domain. For example, a selector named s1 for example.com would be published at s1._domainkey.example.com. The record is a list of tag and value pairs. The most important are v=DKIM1, which declares the version, k=rsa, which declares the key type, and p=, which contains the public key itself encoded in base64.
Splitting long records correctly
A 2048-bit public key is long, and a single DNS TXT string is limited in length. Many providers handle this automatically when you paste the full record, but some require you to split the key into multiple quoted strings within the same TXT record. Split correctly, the receiver joins the strings in order and reads one continuous key. Split incorrectly, with extra spaces or missing characters, verification will fail even though the record looks roughly right.
After saving, wait for DNS to propagate, then query the record externally and compare it character by character with the generated value. Check for stray spaces, a missing p= tag, a doubled domain name, or the wrong record type. An empty p= value revokes a key, so it should only appear when you retire one.
Step 4: Configure Signing on Your Mail Server
Now tell your mail server to sign. On self-hosted systems this is usually done with a signing filter that works alongside the mail transfer agent. Postfix commonly works with OpenDKIM, other transfer agents have equivalent components, and many control panels include DKIM as a built-in option per domain. The names differ, but the configuration always answers the same questions.
- Which domains should this server sign for?
- Which selector should it use for each domain?
- Where is the matching private key stored?
- Which headers should be signed, and is From always included?
- Should the server sign, verify, or do both?
Typically, each domain is mapped to its selector and key file in a key table, senders are mapped to signing rules in a signing table, and the transfer agent is told to pass outgoing mail through the signing filter on a local port or socket. After editing, restart both services and check the logs. Most early problems appear there as permission errors on the key file, a socket that cannot be reached, or a domain missing from the signing table.
Step 5: Check Alignment With Your From Domain
Authentication and alignment are related but not identical. DKIM can pass perfectly for a signing domain that differs from the domain in the visible From address, yet DMARC will still fail, because DMARC asks whether the authenticated domain aligns with the From domain. That distinction surprises many senders when a report shows a passing signature and a failing overall result.
In relaxed alignment, the default and the right choice for most senders, the signing domain and From domain must share the same organisational domain, so a subdomain can sign for its parent. In strict alignment, they must match exactly. To stay safe, sign with the same domain you show in the From address wherever possible, use subdomains deliberately to separate mail streams, and make sure any third-party sender you authorise signs with a domain that aligns with yours, not only with its own.
Step 6: Test Your DKIM Setup Thoroughly
Never assume a new setup works because no error appeared. Test it the way a receiver will. Send a message from the configured system to a mailbox you control at a large provider, open the raw headers, and look for a DKIM result of pass alongside your domain and selector. Many providers summarise this in an Authentication-Results header, which makes checking quick once you know where to look.
- Send separate tests for each sending system and each domain.
- Test plain text and HTML messages, and messages with attachments.
- Check for dkim=pass and the correct signing domain.
- Use a dedicated DKIM testing service for a second opinion.
- Query your DNS record externally to confirm what the world sees.
- Review DMARC aggregate reports after launch for unexpected failures.
Troubleshooting Failed DKIM Signatures
Most failures fall into a handful of repeatable categories. Work through them in order, starting with DNS, then the key, then what happened to the message between signing and delivery.
The public key cannot be found or parsed
This usually means the record is at the wrong address, has not propagated, was published under a doubled domain name, or contains a formatting error such as a broken split or extra space. Query the exact address a receiver would query, built from your selector and domain, and compare the result with the generated record. Fix DNS first, because no server change can compensate for a public key receivers cannot read.
The body or header hash does not match
A body hash mismatch means the body changed after signing. Common causes include a mailing list adding a footer, a security gateway rewriting links, a disclaimer tool appending text, or a system converting line endings. Header mismatches often come from a gateway rewriting the subject or reformatting signed headers. Compare the sent and received raw messages, find the first difference, and move signing to be the last step. Relaxed canonicalisation can make signatures more resilient to harmless handling.
Rotating Your DKIM Keys Safely
Keys should not live forever. Regular rotation limits the damage if a private key is ever exposed and keeps your setup aligned with current expectations for key strength. A safe rotation follows a simple order that avoids any window in which receivers cannot verify your mail.
- Generate a new key pair under a new selector.
- Publish the new public key in DNS and wait for propagation.
- Switch the signer to the new selector and confirm tests pass.
- Leave the old public key published while messages in transit are verified.
- Retire the old key by removing its record or publishing an empty p= value.
Rotating once or twice a year is a sensible routine for many organisations, provided old and new keys overlap long enough for mail in transit to be verified.
DKIM Best Practices Worth Keeping
Sign all legitimate mail streams from your domain, not just your newsletter, and use dedicated subdomains for transactional and marketing mail so a problem with one stream does not damage the other. Monitor DMARC reports continuously, and remember that a clean list, honest subject lines, and a working unsubscribe process still decide how receivers judge you.
Conclusion
Setting up DKIM is a sequence of small, verifiable steps: choose a domain and selector, generate a 2048-bit key, publish the public key carefully in DNS, configure your server to sign, confirm alignment, and test from a receiver's point of view. Each step can be checked before you move to the next.
If you would rather send from infrastructure where authentication, reputation, and high-volume delivery are handled as part of the service, explore our dedicated SMTP email server plans today. You get your own server, full DKIM, SPF, and DMARC support, and a team that understands bulk sending, so your mail is properly signed and ready to reach the inbox.