Setting Up DKIM with Exim
Configuring DKIM (DomainKeys Identified Mail) in Exim ensures that outgoing emails are signed with a digital signature to verify the authenticity of the sender. Here is a step-by-step guide to setting up DKIM with Exim.
For closely related DKIM and Exim topics, see Fixing t_dkim_invalid (DKIM Signature Issue), Exim Syntax Errors — Causes and Fixes, Understanding cm._domainkey — DKIM Selector Example, and check-auth@verifier.port25.com.
Prerequisites
Before you begin:
- Exim Installed:
- Ensure Exim is installed and running on your server.
- Use the following command to check its status:
systemctl status exim - Access to Server and DNS:
- SSH access to your server.
- Control over your DNS settings to publish DKIM public keys.
- Install OpenSSL:
- OpenSSL is required to generate DKIM keys:
sudo apt install openssl
Generate DKIM Keys
Create a Directory for Keys
Choose a directory to store DKIM keys, such as /etc/exim/dkim/:
sudo mkdir -p /etc/exim/dkim
sudo chmod 700 /etc/exim/dkim
Generate a DKIM Key Pair
Replace default with the selector you want to use:
openssl genrsa -out /etc/exim/dkim/default.private 2048
openssl rsa -in /etc/exim/dkim/default.private -pubout -out /etc/exim/dkim/default.public
Set Permissions
Restrict access to the private key:
sudo chmod 600 /etc/exim/dkim/default.private
Extract the Public Key
Format the public key for the DNS record:
awk 'NR > 1 && NR < 10' /etc/exim/dkim/default.public | tr -d '\n' > /etc/exim/dkim/default.txt
The output is the key you will add to your DNS.
Configure DNS for DKIM
Add a TXT Record
Use the following format to create a TXT record in your DNS settings:
default._domainkey.example.com IN TXT "v=DKIM1; k=rsa; p=PUBLIC_KEY"
Replace:
defaultwith the selector you chose.example.comwith your domain.PUBLIC_KEYwith the content from/etc/exim/dkim/default.txt.
Verify DNS Propagation
Check the DKIM record using:
dig TXT default._domainkey.example.com
Configure Exim for DKIM
Edit Exim Configuration
Open the Exim configuration file (/etc/exim/exim.conf or /etc/exim4/exim4.conf):
sudo nano /etc/exim/exim.conf
Add DKIM Settings
Add the following to the configuration:
# DKIM Settings
dkim_domain = ${sender_address_domain}
dkim_selector = default
dkim_private_key = /etc/exim/dkim/default.private
dkim_canon = relaxed
dkim_strict = false
This tells Exim to:
- Use the sender domain for DKIM signing.
- Use the
defaultselector. - Load the private key from
/etc/exim/dkim/default.private.
Save and Exit
Save the file and exit (Ctrl+O, Ctrl+X).
Restart Exim
Apply the changes by restarting Exim:
sudo systemctl restart exim
Test DKIM Configuration
- Send a Test Email:
- Send an email to a DKIM testing service like:
check-auth@verifier.port25.commail-tester.com
- Check Headers:
- Look for the DKIM-Signature header in the email.
- A successful DKIM signature should appear as:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=default; - Review the DKIM Result:
- The test report will indicate if the DKIM check passed.
Troubleshooting
| Issue | Solution |
|---|---|
| No DKIM-Signature Header |
dkim_private_key path is correct. |
| DKIM Validation Fails |
|
| Emails Flagged as Spam |
|
With DKIM configured, your emails will now include a digital signature that improves email authentication and deliverability. Combine DKIM with SPF and DMARC for robust email security.


