Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

What I am trying to achieve - Bottomline: mails to go in inbox rather spam folder.

I have a server which is running postfix (mail server) and I have 3 domains. Mail server is used for both incoming and outgoing mails..

I am signing with opendkim and have DNS records in place.

After a long observation, I've realized that messages are going in spam due to incorrect mailed-by and signed-by assignment.

consider, my mail server to be and 3 other domains are, and

when someone sends an email from , it should display: via



I have observed that mailjet and amazon emails hardly go into spam, the fact is, 'maybe' because the originating hostname / ip reverse resolves to what mailed-by and signed-by are.

Config files:



KeyFile     /etc/opendkim/keys/example1_com/selc
Selector        selc

KeyFile     /etc/opendkim/keys/example2_com/selc
Selector        selc

Canonicalization    simple
Mode            sv
Syslog                  yes
LogWhy                  yes
UMask                   022
UserID                  opendkim:opendkim
KeyTable           /etc/opendkim/KeyTable
SigningTable       /etc/opendkim/SigningTable
ExternalIgnoreList /etc/opendkim/TrustedHosts
InternalHosts      /etc/opendkim/TrustedHosts
Socket                  inet:34562@localhost
X-Header        no

and finally


Where am I missing?

share|improve this question
How does SPF come into this question? – MadHatter Dec 2 '13 at 10:27
By error. Edited. Do you have answer? – Karma Dec 2 '13 at 12:20
No, but if you'd wanted SPF guidance as well I'd've moved to close this question as being overbroad, plus SPF configuration questions are OT as duplicates of the canonical SPF question at…. – MadHatter Dec 2 '13 at 12:28
Yea... I read that answer whilst updating my spf stuff... However, am bit held up with DKIM... If u might know... I have this DKIM for example1 and example2 and when i generate for mail.example and submit that as DKIM it would fail the auth, which ... is logically self-explanatory but... any ideas? – Karma Dec 2 '13 at 13:30

1 Answer 1

up vote 4 down vote accepted

First of all, please remove these values (they aren't needed if you use KeyTable):

KeyFile     /etc/opendkim/keys/example1_com/selc
Selector    selc

KeyFile     /etc/opendkim/keys/example2_com/selc
Selector    selc

Setup your KeyTable like that:


Setup your SigningTable like that (note wildcard matching and mykey1 and mykey2 from KeyTable):

* mykey1
* mykey2

And finally change your opendkim.conf to include SigningTable via refile: prefix (regular expressions support):

SigningTable    refile:/etc/opendkim/SigningTable

And domain record for reference (note recordname1 and recordname2 from KeyTable):

recordname1._domainkey IN TXT "v=DKIM1; g=*; k=rsa; p=..."
recordname2._domainkey IN TXT "v=DKIM1; g=*; k=rsa; p=..."

Additionally, please, check if you have your node hostname (from which you are sending mail) in InternalHosts file:

Again, you can use refile: prefix to be able to add something like:


if you have multiple hosts and do not want to include all of them by hand. If you accept only local mail, you should add localhost here.

You should check log file for DKIM notices about skipping signing if your host is missing in the InternalHosts file.

Example of opendkim.conf:

# Set these values (Syslog, SyslogSuccess, LogWhy) for debugging and check syslog for details
Syslog      yes
SyslogSuccess   yes
LogWhy      yes

UMask       002
UserID      opendkim:opendkim

KeyTable            /etc/opendkim/KeyTable
SigningTable        refile:/etc/mail/SigningTable
InternalHosts       refile:/etc/mail/hosts
share|improve this answer
Hey fantastic! Lemme try out... – Karma Dec 20 '13 at 18:11
mykey1 mykey2 mykey1 and mykey2 = DNS TXT record key names? – Karma Dec 20 '13 at 18:19
What is an InternalHosts. Rest all done... – Karma Dec 20 '13 at 18:24
You have included it in your opendkim.conf: InternalHosts /etc/opendkim/TrustedHosts This file contains all hosts for which messages will be signed. recordname1 and recordname2 are DNS TXT records. mykey1 and mykey2 are for internal usage, for example to link emails to specific keys – GeekMagus Dec 20 '13 at 18:28
UserID opendkim:opendkim KeyTable /etc/opendkim/KeyTable SigningTable refile:/etc/opendkim/SigningTable ExternalIgnoreList /etc/opendkim/TrustedHosts InternalHosts /etc/opendkim/TrustedHosts Socket inet:12345@localhost – Karma Dec 20 '13 at 18:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.