How to set Exim envelope domain to From domain

Solution 1:

Add the rewrite rule to the Exim4 configuration:

*@+local_domains "${local_part}@${domain}" F

The rule rewrites the Envelope-from header to match the From header, allowing DMARC alignment to work correctly. Recommendation is to append it to the end of the section to avoid conflicts with current rules.

You can find this configuration in the file /etc/exim4/conf.d/rewrite/10_from_rewrite or in the section called rewrite/31_exim4-config_rewriting of the file /etc/exim4/exim4.conf.template (for Debian). It depends on the type of your configuration – called single monolithic or split Exim4 config file with possible need to run the command update-exim4.conf.

Restart Exim after reconfiguration using systemctl restart Exim4.


The rule explanation:

  • * of the *@+local_domains = for all "local_parts" e.g. users.
  • +local_domains = for all domains served by Exim4 server (defined in dc_other_hostnames and dc_readhost variables) and not by other domains (redirection attempts etc.).
  • ${local_part}@${domain} composes RFC2822 compliant e-mail address from From field. Variables are described in exim4 documentation – string expansions. You can use just "$header_from:", but addresses in a form as "John Doe <[email protected]>" will fail and get recorded to paniclog because of the "John Doe" part.
  • F = target field of rewrite operation is the Envelope-from. see exim4 documentation – address rewriting.