# Enable DKIM in Postfix on Ubuntu

**URL:** <https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487>\
**Category:** Self-Hosting\
**Tags:** email, how-to\
**Created:** [1 באפריל,‏ 2013,‏ 7:17pm UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487 "2013-04-01T19:17:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [1 באפריל,‏ 2013,‏ 7:17pm UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487/1 "2013-04-01T19:17:45Z")

</div>

I’d like to set up [DKIM](http://www.dkim.org/) to help ensure that email notifications from my self hosted Discourse instance actually get reliably delivered.

> DomainKeys Identified Mail (DKIM) lets an organization take responsibility for a message that is in transit. The organization is a handler of the message, either as its originator or as an intermediary. Their reputation is the basis for evaluating whether to trust the message for further handling, such as delivery. Technically DKIM provides a method for validating a domain name identity that is associated with a message through cryptographic authentication.

How do I do this?

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [1 באפריל,‏ 2013,‏ 7:24pm UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487/2 "2013-04-01T19:24:46Z")

</div>

You’ll need to enable DKIM signing on your MTA of choice that will handle outbound email.

Here at Discourse, we use Postfix on Ubuntu.

### References

- [DKIM main site](http://www.dkim.org/)
- [Ubuntu Postfix/DKIM documentation](https://help.ubuntu.com/community/Postfix/DKIM)

### First-time setup of opendkim:

1. Install opendkim and opendkim-tools:  
`sudo apt-get install opendkim{,-tools}`

2. Make the following changes in `/etc/opendkim.conf`:

3. Add to `/etc/opendkim/TrustedHosts` (adjust as necessary):

4. Add to `/etc/postfix/main.cf`:

5. Add `-l` to daemon options in `/etc/default/opendkim`

6. Reload `opendkim` and `postfix`

### For each domain for which you’ll sign mail

We’ll use [howtogeek.com](http://howtogeek.com) as an example:

1. Generate the signing keys (as root):

2. Add the following to `/etc/opendkim/KeyTable`:

3. Add `howtogeek.com` to `/etc/opendkim/SigningTable`:

4. Add the public key (found in `/etc/opendkim/keys/howtogeek.com/discourse.txt`) to DNS

5. Verify setup:

You can ignore the ‘unsafe permissions’ warning as we know that it’s OK. `opendkim-testkey` complains if the file permissions are anything but 0600, but I see no reason to allow the `opendkim` user to modify the file.

1. Reload opendkim:

Now test! Send a [test email from the Discourse control panel](http://meta.discourse.org/t/how-do-i-enable-dkim-for-discourse-emails/5487/3) and you should see a DKIM header:

```
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=discourse.org;
    s=discourse; t=1375244260;
    bh=qJH3NcptcxBvtKlFtHRUKKT9+KOQ/a4wjqyRN5+Wjac=;
    h=Date:From:Reply-To:To:Subject:List-Id:From;
    b=GtKwkX5mb6Cb4uVE0UDb01imuzPPtruxCK3FVaKyoayYYV
    6G0LJ28nPnBVU0NcdfMAJg8Ox2t48esVvnJGIjCrzB38pOSq
    HFbvNG9WXQ+jQ9aDrOGReVNNI80W+TomfTjR7V0Beo+foeeT
    ikVfXNLxfX/EZIroe9ZfhMGyXq0p0=

```

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [1 באפריל,‏ 2013,‏ 7:52pm UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487/3 "2013-04-01T19:52:42Z")

</div>

Also just as a reminder, **I strongly recommend anyone configuring email in Discourse to send a test email**. You can do this from the admin panel, under Email logs, at the top where the button says “send test email”.

![](https://global.discourse-cdn.com/meta/original/1X/fa1e7abfc08963a2b090741118fa3434c821b53a)

This email contains crucial, _extremely_ important tips to get your Discourse forum email notifications working:

> This is a test email sent from your Discourse forum at:

> [**http://forum.example.org**](http://forum.example.com)
> 
> Email deliverability is complicated. Here are a few important things you should check first:
> 
> - Know how to view the _raw source of the email_ in your mail client, so you can examine the email headers for important clues. in Gmail, it is the “show original” option in the drop-down menu on each mail.
> 
> - **IMPORTANT:** Does your ISP have a reverse DNS record entered to associate the domain names and IP addresses you send mail from? [Test your Reverse PTR record](http://mxtoolbox.com/ReverseLookup.aspx) here. If your ISP does not enter the proper reverse DNS pointer record, it’s very unlikely any of your email will be delivered.
> 
> - Is your domain’s SPF record correct? You can [test your SPF record](http://www.kitterman.com/spf/validate.html) here.
> 
> - Check to make sure the IPs of your mail server are [not on any email blacklists](http://whatismyipaddress.com/blacklist-check).
> 
> - Verify that your email server is _definitely_ sending a fully-qualified hostname that resolves in DNS in its HELO message. If not, this will cause your email to be rejected by many mail services.
> 
> - Configure [DKIM email key signing](http://www.dkim.org/) in your email software, and place the public DKIM key in your DNS records. This is not required, but will significantly improve email deliverability.
> 
> We hope you received this email deliverability test OK!
> 
> Good luck,
> 
> Your friends at [Discourse](http://www.discourse.org)

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [1 באפריל,‏ 2013,‏ 8:03pm UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487/4 "2013-04-01T20:03:14Z")

</div>

In this, as with any other email deliverability stuff, **remember to check the email headers to see if it is working**. For Gmail that is the “Show Original” drop down menu option on the email.

 ![](https://global.discourse-cdn.com/meta/original/1X/0d5a3253a750d26dbfdbb09c262442ee54694581)

When DKIM is configured correctly, you should see a confirmation of some kind in the email headers (using GMail in this example)

```
Authentication-Results: mx.google.com;
   spf=pass (google.com: domain of info@discourse.org designates 64.71.148.3 as permitted sender) smtp.mail=info@discourse.org;
   dkim=pass header.i=@discourse.org

```

When you only have SPF and Reverse PTR configured, you’ll just see

```
Authentication-Results: mx.google.com;
   spf=pass (google.com: domain of info@discourse.org designates 64.71.148.3 as permitted sender) smtp.mail=info@discourse.org

```

The magic phrase you are looking for in the GMail headers specifically is

### `dkim=pass`

---

<div class="post-metadata">

**Author:** ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)\
**Post date:** [24 בספטמבר,‏ 2022,‏ 1:54am UTC](https://meta.discourse.org/t/enable-dkim-in-postfix-on-ubuntu/5487/5 "2022-09-24T01:54:09Z")

</div>

הוצא מהרשימה ב־ב־24 בספטמבר,‏ 2022,‏ 1:54am UTC

Unlisting as this is quite old and we generally recommend people use other services for sending email.
