To sign outgoing mail with OpenDKIM and Postfix, install OpenDKIM, generate a key pair for your domain, publish the public key as a DNS TXT record, and connect Postfix to OpenDKIM as a milter so every outgoing message gets a DKIM-Signature header. DKIM proves the message came from a server authorised to sign for your domain and that the signed parts were not changed in transit.
This is an OpenDKIM Postfix setup for Debian or Ubuntu, using example.com as the domain and mail as the selector. It follows the Postfix, Dovecot and TLS setup.
DKIM (DomainKeys Identified Mail) uses a public key signature:
DKIM-Signature header that names the domain (d=) and the selector (s=).selector._domainkey.domain, and verifies the signature with the public key published there.The selector lets you keep several keys at once, which makes key rotation safe. DKIM works with SPF and DMARC: DMARC passes when SPF or DKIM passes and the domain aligns with the visible From address. Gmail and Yahoo require DKIM for bulk senders, and signing all mail is good practice for any sender.
OpenDKIM runs as a separate daemon and talks to Postfix over a socket using the milter protocol.
Use a 2048-bit RSA key. Old 1024-bit keys are weak, though 2048-bit TXT records are long enough that some DNS panels need them split into quoted strings. The command creates mail.private (keep it secret) and mail.txt (the DNS record).
Edit /etc/opendkim.conf.
Mode sv makes OpenDKIM both sign outgoing mail and verify incoming mail. relaxed/simple tolerates harmless whitespace changes in headers. Create the three tables.
The key table maps a key name to the domain, selector and private key file. The signing table says which sender addresses use which key, so you can add one line per domain. Postfix must be in the opendkim group to reach the socket.
Show the record the tool generated.
Create a TXT record named mail._domainkey.example.com whose value joins the quoted parts into one string: v=DKIM1; h=sha256; k=rsa; p=.... Many DNS panels want only the part inside the quotes, with no line breaks. Wait for DNS to propagate, then test the record and key together.
key OK means the DNS record matches the private key on the server. If it says key not secure, that only means DNSSEC is not enabled and is not an error.
Add the milter to Postfix, then restart both services.
The socket path opendkim/opendkim.sock is relative to Postfix's queue directory, /var/spool/postfix, which matches the Socket line above. Setting milter_default_action = accept keeps mail flowing if OpenDKIM is down, at the cost of sending unsigned mail until you fix it. Use tempfail if you prefer to hold mail instead. non_smtpd_milters makes locally generated mail, such as cron messages, signed as well.
Send a message to a mailbox you control and read the original headers.
dkim=pass is the result you want. You can also send a message to an address provided by an email-testing service and read its report. Check the server side with sudo journalctl -u opendkim -n 30, which logs lines such as DKIM-Signature field added (s=mail, d=example.com).
Common failures are a socket permission error (check the group membership and the directory owner), a DNS record with stray spaces or a missing p= value, a selector mismatch between the key table and DNS, and a message changed after signing, for example by a footer added by a mailing list.
Rotate keys once or twice a year, or at once if a private key could have leaked.
2027a.key.table and signing.table to use the new selector, and reload OpenDKIM.Yes. SPF and DKIM check different things, and DMARC needs at least one of them to pass with a domain that aligns with the From address. Publish both.
A mailing list, security gateway or forwarding rule may alter the message after signing. Mail that is only forwarded without changes normally still verifies.
Use 2048-bit RSA keys, or 1024 bits only if your DNS provider cannot hold longer records. Pick a selector you can change, such as the year or a name like mail.
Sign each domain you send from, by adding a line per domain to the signing and key tables with its own key.
Install OpenDKIM, generate a 2048-bit key, publish the TXT record at selector._domainkey.domain, and configure the key and signing tables. Connect Postfix with smtpd_milters and non_smtpd_milters, then confirm dkim=pass in a real message header and with opendkim-testkey. Rotate keys with a new selector so signing never has a gap.