FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator Emails separator DKIM with Postfix

Topics

On this page

Install DKIM

Edit Config files

DKIM config

Postfix file

DKIM Key Generation

DNS Record Setup

Start Signing

Testing DKIM setup for correctness

Verify DNS Records for DKIM Setup

Verify DKIM Signing

DKIM with Postfix

If mails from your web-server/webapp is having delivery issues, DKIM (DomainKeys Identified Mail) can help you big time.

Its highly recommended to use DKIM for outgoing emails even if your server is not running any kind of mail-hosting.

Install DKIM


			apt-get install opendkim opendkim-tools
		

Edit Config files

DKIM config

Open dkim config file vim /etc/opendkim.conf

Add following lines towards end. Make sure you replace example.com with your domain/subdomain.


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

Next open dkim defaults file vim /etc/default/opendkim

Change default socket path by adding a line like below:


			SOCKET="inet:8891@localhost"
		

Postfix file

Open postfix main config file vim /etc/postfix/main.cf

Add following lines towards end.


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

DKIM Key Generation

Run following commands with mail and example.com matching values used in /etc/opendkim.conf file in earlier step.


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

This command will generate mail.private and mail.txt file. mail.private is private key that will be used to sign outgoing emails. Move it to the location we specified earlier in /etc/opendkim.conf


			cp mail.private /etc/postfix/dkim.key
		

DNS Record Setup

Next, you need to create a TXT record on DNS end. Just check content of mail.txt file created by opendkim-genkey command we ran above.


			cat mail.txt
		

You will see something like below:


			mail._domainkey IN TXT "v=DKIM1; k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYv84GSl0Xp2CrPdFqMZ9ShBDi9Pal9XpfIf7asEENxLRdIka3TONpqtrcCKksROJBNh2G3OVGuoGJ1watQGT46B+zQtjcCI67+WiTlb2D98s1UV3KO7oi/0QH/lH8DzUmrGJUIy3ZBQ9mIu1t6YDyi8y3hlhTILHW7G4HV/VtwQIDAQAB" ; ----- DKIM key mail for example.com
		

TXT record will require NAMS & VALUE.

Use mail._domainkey for NAME and long string in quotes starting from v=DKIM1 as VALUE.

Below is a sample screenshot for a TXT record. User-interface on your end might differ.

TXT-DKIM record-1

If you are editing a previous DNS record, it might take sometime for changes to propogate.

Start Signing

Once al config & setup done, you need to start DKIM service and restart postfix.


			service opendkim start
service postfix restart
		

Testing DKIM setup for correctness

Anything we do, specially for first time, must end with successful testing!

There are many tools for testing. I will mention few of them below.

Verify DNS Records for DKIM Setup

This will ONLY verify if your TXT record is created successfully.

dig command

Classic and easy. You must be having this already. Running…


			dig mail._domainkey.example.com TXT
		

should return a response like…


			;; ANSWER SECTION:
mail._domainkey.exmaple.com. 86400 IN   TXT "v=DKIM1\;" "k=rsa\;" "t=y\;" "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYv84GSl0Xp2CrPdFqMZ9ShBDi9Pal9XpfIf7asEENxLRdIka3TONpqtrcCKksROJBNh2G3OVGuoGJ1watQGT46B+zQtjcCI67+WiTlb2D98s1UV3KO7oi/0QH/lH8DzUmrGJUIy3ZBQ9mIu1t6YDyi8y3hlhTILHW7G4HV/VtwQIDAQAB"
		

Web-based Record Check

You can use http://www.protodave.com/tools/dkim-key-checker/

Use selector  mail and domain example.com there.

Verify DKIM Signing

Test #1 – Email-based

If you have setup keys correctly then you should pass this test.

You can test by simply sending an email to autorespond+dkim@dk.elandsys.com or check-auth2@verifier.port25.com

It’s better to use swaks tools for mail-testing (apt-get install swaks).


			swaks -t check-auth2@verifier.port25.com -f me@example.com
		

Replace me@example.com with your mail id where you would like to receive test results.

Test #2 – Web-based

Better choice will be to use a service like http://www.mail-tester.com/  which gives you a temporary email ID and web-interface to see what happens to the email on receiving end!

For WordPress, its better to test using Check Email plugin as you will get better picture of what happens to mail sent from WordPress!

Mozilla Thunderbird

PREVIOUS

Postfix Queue Management

NEXT


Comments

  1. wayne Avatar

    wayne

    January 6, 2014

    Good day

    I used

    Domain *
    KeyFile /etc/postfix/dkim.key
    Selector mail

    in /etc/opendkim.conf to use the same key for multiple domains

    External link to help.ubuntu.comhttps://help.ubuntu.com/community/Postfix/DKIM#Common_errors_and_fixes
    and added “no_milters” to /etc/postfix/master.cf

    made this line:
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

    look like:
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters

    This prevented opendkim signing messages twice.

    I am curious whether this is sane or not. Remember laziness counts!

    Enjoy your day and thank you for your time.

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 7, 2014

      I never used DKIM like above but in another use-case, I used no_milter to avoid double processing.

      If it’s working, it must be fine! 😉

  2. Niklas K Avatar

    Niklas K

    January 27, 2014

    Thanks so much. I was stuck with other tutorials at entering the Information into DNS.
    Helped me great!!

  3. Joe Avatar

    Joe

    February 15, 2014

    Hello,

    thank you for this usefull tutorial 😀

    i used to create my DKIM

    in External link to www.protodave.comhttp://www.protodave.com/tools/dkim-key-checker/ with selector mail is passed ok!

    but in the External link to www.mail-tester.comhttp://www.mail-tester.com/ web site i have always (-1) for this.

    i have to use selector named default?
    or change something else in settings?

    thank you 🙂

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 17, 2014

      You need to make sure selector and DNS TXT name match. If there is a mismatch above testing tool may throw error.

  4. Evan Avatar

    Evan

    March 5, 2014

    Hi there! I followed your setup to the letter and I am no longer able to send mails. I get a transport error on the Milter serve. Have you got any idea why?

    “postfix/cleanup[3127]: warning: invalid transport name: “inet in Milter service: “inet:localhost:8891″”

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 7, 2014

      Check if your postfix config matches – External link to rtcamp.comhttps://rtcamp.com/tutorials/mail/dkim-postfix-ubuntu/#postfix-file ?

      1. Evan Avatar

        Evan

        March 10, 2014

        Ok So I reset all the config and now it’s working. However, I have another blockage: when I do a HELO test via smtp on the server side (i.e. telnet localhost 25) I can send mails. However, I added my distant application site to mynetworks in order to allow smtp relays. The problem is that the HELO test seems to go well and the message is queued, but the server does nothing. The log file gives no error message either… Any idea?

        1. Rahul Bansal Avatar

          Rahul Bansal

          March 14, 2014

          For HELO issue, please check postfix error log.

  5. Umesh Kumar Avatar

    Umesh Kumar

    March 9, 2014

    t=y in DKIM Key enables test mode, so even if you have DKIM, you are telling it to ignore. Also you can see the mails, you’ll get test mode in it. (when you click show original, it displays dkim =pass (test mode) ).
    Ref; External link to goo.glhttp://goo.gl/j3Fjbp, External link to goo.glhttp://goo.gl/sbSI82

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 14, 2014

      Very usrful info! Thanks for sharing. 🙂

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

LinkedIn

This field is for validation purposes and should be left unchanged.

Email*

SIGN ME UP

Δ


© rtCamp, since 2009. All rights reserved.

Powered by