WhyAs a way to fight spam outgoing email are digitally signed, this allow receiver to verify that the message was actually sent from the domain in question and is not forged or modified.

See also
Build information

Ensure the following options:

mail/opendkim
[x] FILTER             OpenDKIM filter, requires libmilter/Sendmail

Configuration

The following configuration will allow signing of outgoing mail for the domain example.com using the mail selector (signing mail for multiple domains will not be detailed here).

Domain                  Domain
KeyFile                 Private key location
Selector                Selector

On FreeBSD opendkim run by default as mailnull:mailnull (user/group) so for the unix socket creation it is necessary to use the directory /var/run/milteropendkim/ created by the startup script which has the necessary write permission for that user. It is always possible to use an inet socket with an associated IP address instead.

Socket                  Milter communication socket
UMask                   002

Signing key

Now the key is generated using the opendkim-genkey command, this will create 2 files, one with the private key, and one with a DNS record containing the public key. Generated files are named according to the chosen selector (here: main): mail.private and main.txt.

DKIM Key Generation
opendkim-genkey -t -s Selector -d Domain

The file main.private must be moved to the location specified in the KeyFile entry of the opendkim.conf

Moving generated key to its opendkim.conf location
mv Generated private key Private key location in opendkim.conf

The content of the main.txt must be place in the DNS domain zone used for sending our email, this will look as follow:

Selector._domainkey IN      TXT     ( DKIM information
                                  Public key

Integration

Postfix

Now that DKIM is configured, will still need to indicate to our mail server that it needs to sign the outgoing mail, this is done by having our mail server talking to OpenDKIM through the milter protocol

# Milter
milter_default_action   = accept
smtpd_milters           = OpenDKIM communication socket  # From smtpd daemon
non_smtpd_milters       = OpenDKIM communication socket  # From submission

Due to the selected configuration, it is necessary to add the postfix user to the mailnull group to allow communication with the exported unix socket (umask: 002):

Add `postfix` user to `mailnull` group
pw group mod mailnull -m postfix