Skip to content
Authentication7 min read

DKIM: How Email Signing Works

DKIM (DomainKeys Identified Mail) adds a digital signature to your emails, allowing receiving servers to verify that messages actually came from your domain and were not modified in transit.

What is DKIM?

DKIM is an email authentication method that uses public-key cryptography to digitally sign outgoing emails. Think of it as a tamper-evident seal for your messages. When you send an email, your mail server creates a unique signature using a private key that only you control. Recipients can then verify this signature using a public key published in your DNS records.

This cryptographic approach provides two key guarantees:

Authentication

The email genuinely came from the domain claiming to send it, verified through the cryptographic signature.

Integrity

The email content has not been altered since it was signed, protecting against tampering during transit.

How DKIM Works

The DKIM process involves two main steps: signing when sending and verification when receiving.

Signing (Outbound)

  1. Your mail server takes the email content (headers and body)
  2. It creates a hash of this content using a cryptographic algorithm
  3. The hash is encrypted with your domain's private key to create the signature
  4. The signature is added to the email as a DKIM-Signature header

Verification (Inbound)

  1. The receiving server extracts the DKIM-Signature header
  2. It looks up the public key in your domain's DNS records
  3. Using the public key, it decrypts the signature to get the original hash
  4. It calculates its own hash of the received message
  5. If both hashes match, the signature is valid
Key Point: The private key never leaves your mail server. Only the public key is published in DNS, making it impossible for attackers to forge valid signatures.

DKIM Record Structure

DKIM public keys are published as TXT records in DNS. The record is located at a specific subdomain that combines the selector with "_domainkey".

Host: selector._domainkey.example.com
Type: TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...

Record Components

TagRequiredDescription
v=DKIM1YesVersion identifier (always DKIM1)
k=rsaNoKey type (rsa is default, ed25519 also supported)
p=...YesBase64-encoded public key
t=sNoFlags (s = strict mode, no subdomains)
h=sha256NoHash algorithms allowed (sha256 recommended)

The Selector

The selector is a name you choose that identifies which key to use. This allows you to have multiple DKIM keys for different purposes or to rotate keys without disruption.

# Common selector naming conventions
google._domainkey.example.com    # For Google Workspace
s1._domainkey.example.com        # Generic numbered selector
2024-01._domainkey.example.com   # Date-based for rotation
mail._domainkey.example.com      # Generic mail selector

The DKIM-Signature Header

When your mail server signs an email, it adds a DKIM-Signature header. This header contains all the information needed to verify the signature.

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  d=example.com; s=selector1;
  h=from:to:subject:date:message-id;
  bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
  b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB
    4nujwH2vXN6P1ksKU5kMdC1sNTzmJIJv/zMbh5N/N4N/B...

Key Header Tags

TagMeaning
v=1DKIM signature version
a=rsa-sha256Algorithm used (RSA with SHA-256 hash)
c=relaxed/relaxedCanonicalization for header/body (relaxed allows minor changes)
d=example.comSigning domain (must match or be parent of From domain for DMARC alignment)
s=selector1Selector name to find the public key in DNS
h=from:to:subject...List of headers included in the signature
bh=...Body hash (hash of the email body)
b=...The actual signature value (base64 encoded)

Setting Up DKIM

The exact steps vary by email provider, but the general process is:

Step 1: Generate a Key Pair

Most email services generate this for you. If you need to generate your own (for self-hosted mail servers):

# Generate a 2048-bit RSA private key
openssl genrsa -out dkim_private.pem 2048

# Extract the public key
openssl rsa -in dkim_private.pem -pubout -out dkim_public.pem

Step 2: Add the DNS Record

Publish your public key as a TXT record. Your email provider typically gives you the exact record to add.

# Example for Google Workspace
Host: google._domainkey
Type: TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...

# Example for Microsoft 365
Host: selector1._domainkey
Type: CNAME
Value: selector1-example-com._domainkey.example.onmicrosoft.com

Step 3: Enable DKIM Signing

Once DNS propagates (can take up to 48 hours), enable DKIM signing in your email service. This tells your mail server to start signing outgoing messages.

Step 4: Verify the Setup

Send a test email and check the headers to confirm DKIM is working:

Authentication-Results: mx.google.com;
  dkim=pass header.i=@example.com header.s=google header.b=abc123

Common DKIM Issues

Signature Verification Failures

The signature fails to verify at the receiving end. Common causes:

  • DNS record not published or has typos
  • Email was modified in transit (mailing lists, forwarding)
  • Using "simple" canonicalization instead of "relaxed"
  • Clock skew between servers (check the t= timestamp)
Key Rotation Challenges

When rotating to a new key, maintain both old and new keys during the transition:

  • Create the new key with a new selector
  • Publish the new DNS record
  • Wait for DNS propagation (24-48 hours)
  • Switch signing to the new key
  • Keep the old record for 7+ days for delayed emails
DNS Record Length Limits

DNS TXT records have a 255-character string limit. For 2048-bit keys, the record must be split:

v=DKIM1; k=rsa; p="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A..."
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ..."

Most DNS providers handle this automatically, but verify the record is correctly published.

Selector Naming Best Practices

Choose selector names that help with organization and rotation:

  • Include the provider name (google, microsoft, sendgrid)
  • Use date-based names for rotation (2024q1, 202401)
  • Avoid generic names that make tracking difficult
  • Document which selector is used by which service

Summary

  • 1.DKIM uses public-key cryptography to sign emails and prove authenticity
  • 2.The private key signs; the public key (in DNS) verifies
  • 3.Selectors allow multiple keys for different services and rotation
  • 4.DKIM is required for DMARC alignment and helps email deliverability

Resources

Check Your DKIM Configuration

Use our scanner to verify your domain has DKIM configured correctly, along with SPF and DMARC records for complete email authentication.

Scan Your Domain