Prompt
how to set up dkim for email api
Latest observation
Setting up DKIM for an email API usually means: generate a DKIM key pair, publish the public key in DNS, then configure your email provider/API to sign outgoing mail with the private key.
Basic steps
1) Decide your DKIM domain and selector
- Domain: usually your sending domain, e.g.
example.com - Selector: a label to identify the key, e.g.
s1,mail, ordkim1
Your DKIM DNS record will look like:
s1._domainkey.example.com
2) Generate a DKIM key pair
You need:
- Private key → uploaded/configured in your email API
- Public key → published in DNS
If you manage your own mail server, you can generate it with OpenSSL:
openssl genrsa -out dkim-private.key 2048
openssl rsa -in dkim-private.key -pubout -out dkim-public.key
Most email APIs will either:
- generate the key for you, or
- ask you to paste/add a DNS record they provide
3) Publish the public key in DNS
Create a TXT record:
Host/name:
s1._domainkey.example.com
Value:
v=DKIM1; k=rsa; p=PUBLIC_KEY_HERE
The p= value is the public key, usually as one long base64 string without headers/footers.
Example:
v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3...
4) Configure your email API to sign outgoing emails
In your email API/dashboard/config:
- add the selector
- add the domain
- add the private key or connect the DNS record they generated
- enable DKIM signing
The API will add a DKIM-Signature header to outgoing messages.
5) Verify it
Send a test email to:
- Gmail / Outlook and inspect headers
- DKIM testing tools
dig/nslookupfor the DNS record
Check the email headers for something like:
DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=s1; ...
And look for:
dkim=pass
If you’re using a common email API
Some providers have a setup like this:
- SendGrid: authenticate domain, add DKIM CNAME/TXT records
- Mailgun: add DKIM DNS records they provide
- Amazon SES: add CNAME records for DKIM
- Postmark: add DNS records for DKIM
In many cases, the provider gives you DNS records to add, and they handle signing automatically.
Common gotchas
- DNS not propagated yet
- Wrong selector name
- Public key copied incorrectly
- Using the wrong domain (
example.comvsmail.example.com) - Private key not installed in the API/provider
- Key too long for a single TXT record; needs splitting per provider guidance
Important
DKIM alone is not enough for good deliverability. You should also set up:
- SPF
- DMARC
These work together to improve authentication and inbox placement.
If you want, I can give you exact DKIM setup steps for a specific email API like SendGrid, Mailgun, Amazon SES, Postmark, or a self-hosted server.