INSTALL AND CONFIGURE

Install the domain packages:

apt-get install opendkim opendkim-tools

Add the following to /etc/opendkim.conf:

Domain example.com
KeyFile /etc/postfix/dkim.key
Selector dkim
SOCKET inet:8891@localhost

*example.com being your domain

Add the following to /etc/default/opendkim:

SOCKET="inet:8891@localhost"

Add the following to the bottom /etc/postfix/main.cf:

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

Append “no_milters” to the following line in /etc/postfix/master.cf:

-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

Which becomes:

-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters

Now generate the private key and DNS record:

opendkim-genkey -t -s dkim -d example.com

*example.com being your domain

Move the keyfile into place:

mv dkim.private /etc/postfix/dkim.key

Start DKIM and restart Postfix for changes to take effect:

service opendkim start
service postfix restart

Now open the dkim.txt file and add the TXT record to your DNS.

Example of record to add:

TXT dkim._domainkey.example.com v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9rulKo58JIb5h+3MMEnYhlnbuVgRoA4w68R/X7qA2Lfv3RpdrrUb+r7KxemIo6PUIOm6uZ5OymhBgpJ0LAWBHBSJjnFmDXNajSgxMOcvkpgmVCW1/k1kxK864WVVSyFVQPyUImqklY+ws4u+mog3PSbuq2J8NFAnvSwzMg3vT1QIDAQAB

*Notice k=rsa; t=y; have been removed as not needed.

TEST

dig dkim._domainkey.example.com txt

*Replace example.com with your domain

Result should be similar to:

dig dkim._domainkey.twitter.com txt

; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> dkim._domainkey.twitter.com txt
;; global options: +cmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;dkim._domainkey.twitter.com. IN TXT

;; ANSWER SECTION:
dkim._domainkey.twitter.com. 599 IN TXT "v=DKIM1\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrZ6zwKHLkoNpHNyPGwGd8wZoNZOk5buOf8wJwfkSZsNllZs4jTNFQLy6v4Ok9qd46NdeRZWnTAY+lmAAV1nfH6ulBjiRHsdymijqKy/VMZ9Njjdy/+FPnJSm3+tG9Id7zgLxacA1Yis/18V3TCfvJrHAR/a77Dxd65c96UvqP3QIDAQAB"

;; Query time: 34 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Jun 23 10:54:08 2015
;; MSG SIZE rcvd: 285

Full credit for this post goes to http://www.exratione.com/2014/07/setting-up-spf-and-dkim-for-an-ubuntu-1404-mail-server/

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk.