Configure DKIM on Postfix

Here are steps to configure DKIM on Postfix.

I configure DKIM on Postfix using the Ubuntu.

1. Install dkim

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install opendkim opendkim-tools

2. Configure /etc/opendkim.conf

Domain              yourdomain.com
KeyFile             /etc/mail/mail.private
Selector            mail

3. Configure /etc/default/opendkim file

Add to the end of the file.

SOCKET="inet:8891"

4. Configure /etc/postfix/main.cf file

Add these configuration options to the end of the main.cf file.

# DKIM
milter_default_action = accept
milter_protocol = 2
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891

5. Create directory /etc/mail and go there with cd

6. Generate keys in /etc/mail

sudo opendkim-genkey -t -s mail -d youdomain.com

After generating keys you’ll have mail.private and mail.txt in the directory. mail.private is your private key and mail.txt is the public key that you should set as TXT record of the domain.

7. Configure your domain TXT record for DKIM

mail.txt contains what you should set for the domain. It contains something like this:

mail._domainkey IN TXT "v=DKIM1; k=rsa; t=y; p=MIG...QAB" ; 
----- DKIM key mail for youdomain.com

This means that you need to create TXT record for you domain that has mail._domainkey as a “host name” and v=DKIM1; k=rsa; t=y; p=MI…AQAB as a “ip address/url”.

7. Start opendkim and restart Postfix

sudo service opendkim start
sudo service postfix restart

8. Useful links

help.ubuntu.com/community/Postfix/DKIM