Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| email:configure-dkim-spf-dmarc [2025/03/05 20:07] – willy | email:configure-dkim-spf-dmarc [2025/07/24 13:58] (current) – [DMARC (Domain-based Message Authentication, Reporting & Conformance)] willy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Configure proper mail delivery ====== | + | ====== |
| You need access to your domain DNS records, this is mandatory. | You need access to your domain DNS records, this is mandatory. | ||
| Line 37: | Line 37: | ||
| ===== DKIM (Domain Keys Identified Mail) ===== | ===== DKIM (Domain Keys Identified Mail) ===== | ||
| - | Run the following command | + | OpenDKIM provides great documentation [[http:// |
| + | |||
| + | You need to choose a // | ||
| <code bash> | <code bash> | ||
| - | emerge | + | cd / |
| + | opendkim-genkey | ||
| </ | </ | ||
| - | This command | + | This will create two files: **mydomain.com.private**, which contains the secret key, and **mydomain.com.txt** which contains the DKIM public signature that you need to incorporate in your DNS as a TXT record. |
| - | Note the output: | + | === DNS record === |
| + | |||
| + | As an example consider | ||
| < | < | ||
| - | emerge | + | mydomain.com._domainkey |
| + | " | ||
| + | </ | ||
| + | You need to create a new TXT record in your DNS zone with // | ||
| - | Ready to configure mail-filter/ | + | === Postfix setup === |
| - | Enter the selector name (default external.mydomain.com): mydomain.com | + | OpenDKIM acts as a //milter//, which means a mail filter, for Postfix. The postfix configuration described [[email:configure-postfix|here]] already include the required lines under the OpenDKIM setup comment. |
| - | * Make sure you have the following settings in your / | + | === Socket Setup === |
| - | | + | |
| - | | + | |
| - | * If you are using Postfix, | + | For security reasons |
| - | | + | |
| - | | + | The solution is to add a new group, called |
| - | | + | <code bash> |
| - | * After you configured your MTA, publish your key by adding this TXT record | + | groupadd dkimsocket |
| - | mydomain.com._domainkey | + | usermod |
| - | "p=<mykey>" ) ; ----- DKIM key mydomain.com for (your domain) | + | usermod |
| - | * t=y signifies you only test the DKIM on your domain. See following page for the complete list of tags: | + | usermod |
| - | | + | |
| </ | </ | ||
| - | Now, setup the DNS record as specified by the output of the command. | + | === Final wrapup === |
| + | Let's wrap it all up with the following **/ | ||
| + | <file - opendkim.conf> | ||
| + | Syslog | ||
| + | SyslogSuccess | ||
| + | Canonicalization | ||
| + | SendReports | ||
| + | PidFile / | ||
| + | Socket local:/ | ||
| + | UMask 0117 | ||
| + | UserID opendkim: | ||
| + | AutoRestart | ||
| + | AutoRestartRate | ||
| + | Mode sv | ||
| + | # Use the following lines for a single domain/ | ||
| + | Domain | ||
| + | Selector | ||
| + | KeyFile | ||
| + | # Use the following lines for multiple domain/ | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | </ | ||
| + | |||
| + | If you want to use multiple domains and selectors, you need to create the table files and put the multiple references there. Check the official OpenDKIM documentation linked above. | ||
| + | |||
| + | === Start & Autostart OpenDKIM === | ||
| + | |||
| + | <code bash> | ||
| + | rc-update add opendkim default | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | === Test your DKIM setup === | ||
| + | |||
| + | After your DNS record has propagated, you can test it with: | ||
| + | <code bash> | ||
| + | opendkim-testkey -d mydomain.com -s mydomain.com -k mydomain.com.private -vvv | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== DMARC (Domain-based Message Authentication, | ||
| + | |||
| + | OpenDMARC sample configutation can be found [[https:// | ||
| + | |||
| + | This is pretty easy to setup, just edit the **/ | ||
| + | <file - opendmarc.conf> | ||
| + | AuthservID mydomain.com | ||
| + | FailureReports true | ||
| + | RejectFailures false | ||
| + | SPFSelfValidate yes | ||
| + | Socket local:/ | ||
| + | SoftwareHeader true | ||
| + | Syslog true | ||
| + | SyslogFacility mail | ||
| + | TrustedAuthservIDs mail.mydomain.com | ||
| + | HistoryFile / | ||
| + | UMask 0002 | ||
| + | UserID opendmarc | ||
| + | PidFile / | ||
| + | IgnoreAuthenticatedClients true | ||
| + | </ | ||
| + | |||
| + | === DNS record | ||
| + | |||
| + | A DMARC DNS record can be pretty simple or pretty complex. [[https:// | ||
| + | |||
| + | The following is a simple example that you can start from: | ||
| + | < | ||
| + | _dmarc IN TXT ( " | ||
| + | </ | ||
| + | |||
| + | where: | ||
| + | * p: policy, you want reject here most probably | ||
| + | * rua: email address to sent aggregate reports to (optional) | ||
| + | * ruf: email address to sent failure reports to (optional) | ||
| + | |||
| + | === Postfix setup === | ||
| + | |||
| + | OpenDMARC acts as a //milter//, which means a mail filter, for Postfix. The postfix configuration described [[email: | ||
| + | |||
| + | === Start & Autostart OpenDMARC === | ||
| + | |||
| + | <code bash> | ||
| + | rc-update add opendmarc default | ||
| + | /etc/init.d/opendmarc start | ||
| + | </ | ||
| + | |||