Postfix / sendmail config for DKIM, SPF and DMARC Tutorial Guide E-mail Delivery for 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/

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  Let's say the From Address is "", this is a problem becasue presumably you've signed the e-mail for "" but some e-mail providers will also check the Return-path domain of "" 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, then the return path is the, and this obviously breaks more strict DKIM checks because e-mail servers like 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, this will be the domain set in the Return-path and the MASQUERADE_DOMAIN is, you can add more lines with extra domains you want to rewrite.

dnl MASQUERADE_AS(`')dnl
dnl FEATURE(masquerade_entire_domain)dnl
dnl MASQUERADE_DOMAIN(abc123)dnl


To apply the changes update like this:

We have to generate the new config file


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 and your from address is, 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 and on your server that sends out). 



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 resize a pdf without losing much quality in Linux Mint Ubuntu Debian Redhat Solution
  • qemu: could not load PC BIOS 'bios-256k.bin' solution
  • Proxmox How To Custom Partition During Install
  • Hyper-V Linux VM Boots to Black Screen, Storage, NIC Not Found Issues
  • Ubuntu Mint How to Fix Missing/Broken /dev and /dev/pts which causes terminal to immediately close exit and not work
  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm