I got DKIM setup on my mail server (postfix and ubuntu) so it signs outgoing emails. I used these instructions: https://help.ubuntu.com/community/Postfix/DKIM

However, I need it to sign emails from any domain (in the From address) and not just my own. I'm building an email newsletter service and clients will be sending their own email through the server.

First I set "Domain *" in /etc/dkim-filter.conf. This got it to include the DKIM headers in all outgoing emails, no matter what the domain.

However, the verification check fails on gmail because it is checking the domain in the from address, and not my domain (and dns record). Does anyone know how to do this?


4 Answers 4


Ok I managed to figure this out on my own, but I wanted to post the steps here for posterity because there was zero documentation on this (that I could find) and it was practically guess and check.

After I set "Domain *" as described above, it would sign it like this:

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=clientdomain.com;
    s=main; t=1250005729;

notice the "d=clientdomain.com". It was generating this based on the from address in the email, where the from address was something like "[email protected]". Obviously if it checked the client's domain and not mine no DNS TXT record was there and the verification would fail.

So anyway I found out in this documentaion that you can set a KeyList parameter. http://manpages.ubuntu.com/manpages/hardy/man5/dkim-filter.conf.5.html

It didn't really describe what I wanted to do, but I figured I'd play with it. I commented out KeyFile and set KeyList to "/etc/mail/dkim_domains.key" which is an arbitrary file name I made up. I then created that file and put this in it "*:feedmailpro.com:/etc/mail/dkim.key". This tells it for any client domain, sign it with my domain (feedmailpro.com), and use the dkim.key file.

Restarted DKIM and postfix

sudo /etc/init.d/dkim-filter restart
sudo /etc/init.d/postfix restart

Now this is the key it generated when I sent a test email.

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=feedmailpro.com;
    s=dkim.key; t=1250005729;

Improvement, you see the d= now is set to my domain (even though the from address of the email was not my domain). However s= got changed to "dkim.key" instead of the selector I chose in dkim-filter.conf. In the original setup instructions I'd set the selector to "mail". That was weird, but I noticed it changed it to the filename of my key, dkim.key.

So I went and renamed "/etc/mail/dkim.key" to "/etc/mail/mail". Also updated the reference to it in "/etc/mail/dkim_domains.key".

Restart dkim-filter and postfix again same as above, and now it started working. Here is the final header which signs correctly using the right selector (apparently based off the filename of the key).

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=feedmailpro.com;
    s=mail; t=1250006218;

Now s=mail is right, and d=feedmailpro.com is right. It works!

Overall this was way harder than I expected and there seemed to be zero documentation on how to do this (signing for all outgoing domains), but I guess it's open source software so I can't complain.

One final note, to check if the TXT DNS record was setup correctly you can do a command like with your domain

dig mail._domainkey.feedmailpro.com TXT

May need to install dig (sudo apt-get install dig). If you're using Slicehost manager to add the DNS entry, you'd enter the TXT record like this.

Type: TXT
Name: mail._domainkey
Data: k=rsa; t=s; p=M5GfMA0...YOUR LONG KEY...fIDAQAB
TTL seconds: 86400

I don't really understand why the name is set to "mail._domainkey" without a period on the end or without my domain, like "mail._domainkey.feedmailpro.com". But whatever, it seems to work so I'm happy.

If you're trying to duplicate this, here are the instructions I started with: https://help.ubuntu.com/community/Postfix/DKIM

  • 1
    One thing the guide at ubuntu.com fail to mention is that once you got it working, change t=y to t=n in the TXT record to state that it is not a test.
    – 3molo
    Apr 4, 2011 at 7:45
  • There are some good resources out there for using the SigningTable, etc. For example, blog.tjitjing.com/index.php/2012/03/… (excellent) and even the opendkim readme, opendkim.org/opendkim-README
    – rfay
    Feb 19, 2013 at 17:26
  • @3molo well , it actually says "The selector used in the signature will be the filename portion of keypath" , in the documentation , opendkim.org/opendkim.conf.5.html Jan 14, 2015 at 11:04
  • Yeah, it also took me a long time to make it work. I ended up doing the same thing as you, however it could be interesting to generate a key for each domain and them store them in a MySQL DB and tune OpenDKIM to sign the emails from there... fossies.org/linux/opendkim/opendkim/README.SQL (of course we would need to ask our final clients to add the TXT to their domains...)
    – TCB13
    Nov 22, 2015 at 15:21

Inspired by Brian Armstrong's answer for dkim-filter here's how I did this for OpenDKIM.


Syslog          yes
UMask           002
KeyTable        /etc/mail/dkim_key_table
SigningTable    refile:/etc/mail/dkim_signing_table

Note that SigningTable has refile: in it's definition, this specifies that the file includes regular expressions; in our case the * wildcard.


keyname  example.com:selector:/etc/mail/selector.key

Here keyname is used to match the key between this file and the dkim_signing_table file. In my real file I named this the same as my selector.

example.com and selector should be replaced which the domain and selector that you wish to be used in your signature's d= and s= respectively.


*   keyname

This file simple maps address found in the From: header to a key in the dkim_key_table. In this case we want all email's sent via this server to be signed with the same key, so a * wildcard is used.

  • for those who get "no signing table match in OpenDKIM " serverfault.com/q/569823/115907 Jan 14, 2015 at 14:08
  • If anyone gets to this answer (great answer, btw! taught me what I needed) and is looking to send from two different domains with different keys, that can be done like this: KeyTable file: "tagone._domainkey.firstdomain.com firstdomain.com:tagone:/etc/opendkim/keys/firstdomain.com/tagone tagtwo._domainkey.seconddomain.com seconddomain.com:tagtwo:/etc/opendkim/keys/seconddomain.com/tagtwo" SigningTable: "*@firstdomain.com tagone._domainkey.firstdomain.com *@seconddomain.com tagtwo._domainkey.seconddomain.com" Each file is 2 lines (comments don't save linebreaks here) Mar 15, 2017 at 14:12
  • or: SigningTable csl:*=keyname KeyTable csl:keyname=example.com:selector:/etc/mail/selector.key
    – danblack
    Aug 19, 2018 at 5:37
  • This is still not enough in cases where the SMTP session is not authenticated (opendkim checks {auth_type} milter macro before signing).—See my answer. Feb 5, 2022 at 16:30

Old thread but maybe someone else who finds this has a use to knowing the 2.x version of opendkim works with KeyTable instead of KeyList.

You can convert your KeyList file with the opendkim-convert-keylist tool (http://manpages.ubuntu.com/manpages/lucid/man8/opendkim-convert-keylist.8.html)

You can read more about the implementation of KeyTable on the opendkim man page: (http://www.opendkim.org/opendkim.conf.5.html)

  • 2
    Please summarize the article that you linked, quoting any relevant code segments or configuration blocks. Sites can change in the future or fail to load for any number of reasons. Dec 23, 2013 at 17:44

I don't really understand why the name is set to "mail._domainkey" without a period

Documentation for DKIM filter is usually installed in thre unix man format. Only Google does know it :-) I also had a problem.

man dkim-filter.conf
man dkim-filter
man dkim-genkey

man dkim-stats
man dkim-testkey
man dkim-testssp

I tried it on Debian. If it is not not actually in your distibution, you can download source tarball and easy read doc.

man dkim-milter-2.8.3/dkim-filter/dkim-filter.conf.5



I don't really understand why the name is set to "mail._domainkey" without a period

So that you can use exacttly the same in both DNS records of different domains.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .