Authentication
Email authentication prevents forgery. People can still send unsolicited email, but they can’t fake who it’s from. If you set up a Relay for Postfix, the relayer is doing it for you. But otherwise, proceed onward to prevent your outgoing mail being flagged as spam.
You need three things
- SPF: Server IP addresses - which specific servers have authorization to send email.
- DKIM: Server Secrets - email is signed so you know it’s authentic and unchanged.
- DMARC: Verifies the address in the From: aligns with the domain sending the email, and what to do if not.
SPF
SPF, or Sender Policy Framework, is the oldest component. It’s a DNS TXT record that lists the servers authorized to send email for a domain.
A receiving server looks at a messages’s return path (aka RFC5321.MailFrom header) to see what domain the email purports to be from. It then looks up that domain’s SPF record and if the server that sent the email isn’t included, the email is considered forged.
Note - this doesn’t check the From: header the user sees. Messages can appear (to the user) to be from anywhere. So it’s is mostly a low-level check to prevent spambots.
The DNS record for your Postfix server should look like:
Type: "TXT"
NAME: "@"
Value: "v=spf1 a:mail.your.org -all"
The value above shows the list of authorized servers (a:) contains mail.your.org. Mail from all other servers is considered forged (-all).
To have your Postfix server check SPF for incoming messages add the SPF policy agent.
sudo apt install postfix-policyd-spf-python
sudo tee -a /etc/postfix/master.cf << EOF
policyd-spf unix - n n - 0 spawn
user=policyd-spf argv=/usr/bin/policyd-spf
EOF
sudo tee -a /etc/postfix/main.cf << EOF
policyd-spf_time_limit = 3600
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
check_policy_service unix:private/policyd-spf
EOF
sudo systemctl restart postfix
DKIM
DKIM, or DomainKeys Identified Mail, signs the emails as they are sent ensuring that the email body and From: header (the one you see in your client) hasn’t been changed in transit and is vouched for by the signer.
Receiving servers see the DKIM header that includes who signed it, then use DNS to check it. Unsigned mail simply isn’t checked. (There is no could-but-didn’t in the standard).
Note - There is no connection between the domain that signs the message and what the user sees in the From: header. Messages can have a valid DKIM signature and still appear to be from anywhere. DKIM is mostly to prevent man-in-the-middle attacks from altering the message.
For Postfix, this requires installation of OpenDKIM and a connection as detailed here. Make sure to sign with the domain root.
https://tecadmin.net/setup-dkim-with-postfix-on-ubuntu-debian/
Once you’ve done that, create the following DNS entry.
Type: "TXT"
NAME: "default._domainkey"
Value: "v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkq..."
DMARC
Having a DMARC record is the final piece that instructs servers to check the From: header the user sees against the domain return path from the SPF and DKIM checks, and what to do on a fail.
This means mail “From: [email protected]” sent though mail.your.org mail servers will be flagged as spam.
The DNS record should look like:
Type: "TXT"
NAME: "_dmarc"
Value: "v=DMARC1; p=reject; adkim=s; aspf=r;"
- p=reject: Reject messages that fail
- adkim=s: Use strict DKIM alignment
- aspf=r: Use relaxed SPF alignment
Reject (p=reject) indicates that email servers should “reject” emails that fail DKIM or SPF tests, and skip quarantine.
Strict DKIM alignment (=s) means that the SPF Return-Path domain or the DKIM signing domain must be an exact match with the domain in the From: address. A DKIM signature from your.org would exactly match [email protected].
Relaxed SPF alignment (=r) means subdomains of the From: address are acceptable. I.e. the server mail.your.org from the SPF test aligns with an email from: [email protected].
You can also choose quarantine mode (p=quarantine) or report-only mode (p=none) where the email will be accepted and handled as such by the receiving server, and a report sent to you like below.
v=DMARC1; p=none; rua=mailto:[email protected]
DMARC is an or test. In the first example, if either the SPF or DKIM domains pass, then DMARC passes. You can choose to test one, both or none at all (meaning nothing can pass DMARC) as the the second DMARC example.
To implement DMARC checking in Postfix, you can install OpenDMARC and configure a mail filter as described below.
https://www.linuxbabe.com/mail-server/opendmarc-postfix-ubuntu
Next Steps
Now that you are hadnling email securely and authentically, let’s help ease client connections
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.