August 2014
« Jul   Sep »

Adding Multiple SMTP servers : Customizing selector on OpenDKIM

Recently one of my friends is setting up mutliple outbound SMTP servers for his project. But He does not have enough domain access and his primary domain is already being using another DKIM Keys (default._domainkey) for business email purpose.

His challenge is to seup another trusted outbound email server without affecting the primary Email configuration.


1. Trusting another subdomain for sending outboud email
2. Adding SPF record for this subdomain.
3. Create a separate DKIM txt for this subdomain.

Hope you have completed OpenDKIM server using this link

Here I’m using a test domain for this attempt.

Following things has to be done.

a. a Create new selector for new outbound server.

mkdir /etc/opendkim/keys/
   opendkim-genkey -D /etc/opendkim/keys/ -d -s cloud
   chown -R opendkim.opendkim /etc/opendkim/keys/
   cp /etc/opendkim/keys/ /etc/opendkim/keys/default

Note : This is the file “/etc/opendkim/keys/default” which OpenDKIM init script is using. So that we need to overwrite it with new selector.

b. Update the Keytable entry (/etc/opendkim/KeyTable).
While you declaring the private key file in KeyTable file, you may need to mention the which selector to be used for this subdomain. Here I’m using the selector name to “cloud“. Pls note that name is mention in between the domain name and Key file location added in the KeyTable.

 cat /etc/opendkim/KeyTable

It is very important that you mention the selector (here cloud) name in between the domain key DNS and private key file mention in the KeyTable.

c. Restart Both OpenDKIM and postfix service

service opendkim restart && service postfix restart

D. DNS update to be set for

1. Create a DNS subdomain ( record for email server. Set a FQDN for outbound SMTP (

2. Set spf record which includes the outbound server ip and your FQDN hostname. You may use Microsft SPF record for creating SPF easily.

 TXT Record                     Value
     cloud                          v=spf1 a ptr ip4: ~all

3. Create a DKIM key record “” using the txt file and set the value inside the folder in which you created Public key (/etc/opendkim/keys/

Note : you need to copy the string value starting from the letter “p” ie “p=MIGfMA0GCSq” without quotes.

    TXT Record                       Value          p=MIGfMA0GCS......... phKwoRwIDAQAB

4. set another TXT record for “adsp._domainkey” having the value “dkim=unknown”

 TXT Record                     Value
       adsp._domainkey                dkim=unknown

You almost done now !! It’s the time to test.

How do I verify my DKIM both system and DNS are working correctly locally

[root@smtp ec2-user]# opendkim-testkey -vvv -d
opendkim-testkey: using default configfile /etc/opendkim.conf
opendkim-testkey: key loaded from /etc/opendkim/keys/
opendkim-testkey: checking key ''
opendkim-testkey: key not secure
opendkim-testkey: key OK
[root@smtp ec2-user]#

How do I check the sfp values are set properly

[root@smtp ec2-user]# host -t TXT descriptive text "v=spf1 ip4: ~all"
[root@smtp ec2-user]#

How do I check DKIM Key DNS is properly set

[root@smtp ec2-user]# dig +short TXT
[root@smtp ec2-user]#

This shows you have a perfect setup at DNS side. Now it’s the time to verify new “selector” is signed with all the outgoing emails.

Sending a test mail using SendEmail commandline tool

[root@smtp ec2-user]# /usr/bin/sendEmail -f  -t   -cc   -s localhost   -u DKIM Key setup for Subdomain     -l /var/log/sendEmail  -o message-content-type=auto  -m "mail body"
Aug 30 14:58:56 smtp sendEmail[970]: Email was sent successfully!  From: <> To: <> Cc: <> Subject: [DKIM Key setup for Subdomain] Server: [localhost:25]

Verifying the signature and selector is added to each mail.

[root@smtp ec2-user]# tail -f tail -f /var/log/maillog
Aug 30 14:59:01 ip-10-170-25-242 postfix/smtpd[936]: 7741160EB4: client=localhost[::1], sasl_method=LOGIN, sasl_username=test
Aug 30 14:59:01 ip-10-170-25-242 postfix/cleanup[946]: 7741160EB4: message-id=<>
Aug 30 14:59:01 ip-10-170-25-242 opendkim[32326]: 7741160EB4: DKIM-Signature field added (s=cloud,
Aug 30 14:59:01 ip-10-170-25-242 postfix/qmgr[32424]: 7741160EB4: from=<>, size=596, nrcpt=1 (queue active)
Aug 30 14:59:01 ip-10-170-25-242 postfix/smtpd[936]: disconnect from localhost[::1]
Aug 30 14:59:01 ip-10-170-25-242 postfix/smtp[948]: connect to[2607:f8b0:400e:c04::1b]:25: Network is unreachable



Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>