Postfix / sendmail config for DKIM, SPF and DMARC Tutorial Guide E-mail Delivery for Hotmail.com Gmail.com and More HowTo

This will be the goto to help solve e-mail delivery issues and talk about many practical issues that happen between developers, admins and scripts that send e-mail and do things that may not be acceptable or cause deliverability problems.

Sendmail Stuff

Edit /etc/mail/sendmail.mc

The problem is that if you send directly out from the server using the mail function, the Return-path of the e-mails will be username@thehostnameoftheserver.com.  Let's say the From Address is "hellothere@cooldomain.com", this is a problem becasue presumably you've signed the e-mail for "cooldomain.com" but some e-mail providers will also check the Return-path domain of "thehostnameoftheserver.com" and find it does not match and there is no signature for the hostname and this will cause e-mails to be rejected or sent to spam.

So if your server's hostname is abc123.com, then the return path is the user@abc123.com, and this obviously breaks more strict DKIM checks because e-mail servers like gmail.com will also expect a DKIM signature for the hostname of the server.

To make things worse, a lot of times the people/devs that generate these e-mails may not have access to the server or may not be allowed to change the hostname.

Fix it Using Sendmail's MASQUERADE

Below we can fix this by using MASUERADE_AS with realtechtalk.com, this will be the domain set in the Return-path and the MASQUERADE_DOMAIN is abc123.com, you can add more lines with extra domains you want to rewrite.

dnl MASQUERADE_AS(`realtechtalk.com')dnl
dnl FEATURE(masquerade_entire_domain)dnl
dnl MASQUERADE_DOMAIN(abc123)dnl

 

To apply the changes update sendmail.cf like this:

We have to generate the new config file

m4 sendmail.mc

Restart the sendmail service.

systemctl restart sendmail

OpenDKIM Settings

Be sure to set this option for /etc/opendkim.conf as this will sign for multiple domains/hosts in the e-mail:

MultipleSignatures Yes

Eg. if your return-path is abc123.com and your from address is hello.com, both need to be signed or they will fail DMARC and possibly be blocked or sent to spam.  This also assumes that you should correctly have the keys and configuration to sign all domains that may be a part of the e-mail (eg. our example should mean that you have keys for abc123.com and hello.com on your server that sends out). 

 


Tags:

postfix, sendmail, config, dkim, spf, dmarc, tutorial, hotmail, gmail, howtothis, goto, developers, admins, scripts, acceptable, deliverability, edit, etc, mc, server, mails, username, thehostnameoftheserver, quot, hellothere, cooldomain, becasue, presumably, ve, providers, domain, hostname, rejected, spam, abc, user, strict, servers, devs, generate, masquerade, masuerade_as, realtechtalk, masquerade_domain, domains, rewrite, dnl, masquerade_as, feature, masquerade_entire_domain, update, cf, restart, systemctl,

Latest Articles

  • How To Emulate Android in Linux
  • How to use KVM and GUI inside Docker
  • python spacey ERROR: No matching distribution found for thinc<8.4.0,>=8.3.12
  • Debian 11 security repo fixes due to EOL
  • MySQL vs MariaDB how to create a socket user tutorial
  • Ubuntu Linux Mint Desktop Dark Black Cannot See Solution
  • How to combine .txt ACLs without breaking things
  • How to ping all of Googlebot's IPs script
  • 'virtio0' uses a qcow2 feature which is not supported by this qemu version: QCOW version 3
  • Linux bash script to get the IP of a list of hostnames
  • How To Use Camera Webcam in Docker for OBS Studio etc...
  • Computer Server Won't Post Boot Or Enter BIOS Setup After Installing RAID SAS or GPU Card etc..
  • How To Test PHP Scripts from CLI with GET variables/query string
  • apt-cache how to see all available versions of a package in Debian Ubuntu Mint
  • Virtualbox VBox Guest-utils drag and drop files stops working with Windows VMs
  • How To Remove Ubuntu Netplan and Go Back to /etc/network/interfaces
  • How To Force Flash an AMD Instinct GPU To Another Model Using Debian Ubuntu Mint Linux
  • How To compile ollama from source to use unsupported AMD GPU with rocm in Ubuntu Debian
  • QEMU KVM Virtio GPU Windows Cannot Select 1080P
  • Linux Gnome Desktop Ubuntu Mint Debian Gets Slower After Weeks