DKIM Postfix Setup

DKIM Postfix Setup


OpenDKIM is an open source implementation of the DKIM (Domain Keys Identified Mail) sender authentication system proposed by the E-mail Signing Technology Group (ESTG), now standardized by the IETF (RFC6376). Basically DKIM means digitally signing all messages on the server to verify the message actually was sent from the domain in question and is not spam or phishing (and has not been modified). Check DKIM Email Security Standard for more details. On we go with DKIM Postfix Setup.

OpenDKIM Setup

First of all, let’s install opendkim. Adjust values to match your domain:

# apt-get install opendkim opendkim-tools
# mkdir -pv /etc/opendkim/
# chown -Rv opendkim:opendkim /etc/opendkim
# chmod go-rwx /etc/opendkim/*
# cd /etc/opendkim/
# opendkim-genkey -r -h rsa-sha256 -d -s mail
# mv -v mail.private mail
# cat mail.txt
mail._domainkey IN TXT ( "v=DKIM1; h=rsa-sha256; k=rsa; s=email; "

Apparently “h=rsa-sha256” is wrong, change it to h=sha256. Also, be sure you have that subdomain and all necessary fields: 3596 IN TXT "v=DKIM1;h=sha256;k=rsa;s=email;p=MIGf...

Set that in your DNS server. Than configure postfix to use that key:

# nano /etc/opendkim/KeyTable
# nano /etc/opendkim/SigningTable
# nano /etc/opendkim/TrustedHosts
# nano /etc/opendkim.conf
## opendkim.conf -- configuration file for OpenDKIM filter
Canonicalization relaxed/relaxed
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
KeyTable refile:/etc/opendkim/KeyTable
LogWhy Yes
MinimumKeyBits 1024
Mode sv
PidFile /var/run/opendkim/
SigningTable refile:/etc/opendkim/SigningTable
Socket inet:8891@localhost
Syslog Yes
SyslogSuccess Yes
TemporaryDirectory /var/tmp
UMask 022
UserID opendkim:opendkim
# nano /etc/postfix/ 
#add to the bottom
smtpd_milters = inet:
non_smtpd_milters = $smtpd_milters
milter_default_action = accept

To set fields used in signing, use SignHeaders and OversignHeaders:

SignHeaders From,Sender,To,CC,Subject,Date
OversignHeaders From,Sender,To,CC,Subject,Date

Edit default opendkim:

nano /etc/default/opendkim

Restart everything:

service opendkim restart
service postfix restart

That’s it on DKIM Postfix Setup. Everything should be up and running. Use some mailbox provider that uses DKIM, like GMail, to test. Send an email, look for “Authentication-Results”. You should be able to find “dkim=pass”. If it’s missing, re-check your configuration.


Aside SPF, DKIM is a common authentication method used worldwide, a standard. You can survive without it, but setting DKIM up will increase your Security, domain reputation and furthermore probability that the email is going to get delivered successfully.