Q0801 - Exim/exim GitHub Wiki

Q0801

Question

How can I get Exim to strip the hostname from the sender's address?

Answer

If you set up a rewriting rule in the following form:

*@*.your.domain  [email protected]

then Exim will rewrite all addresses in the envelope and the headers, removing anything between @ and your.domain. This applies to all messages that Exim processes. If you want to rewrite sender addresses only, the the rule should be

*@*.your.domain  [email protected]  Ffrs

This applies the rule only to the envelope sender address and to the From:, Reply-to:, and Sender: headers.

The same rules can also be used if you want to ensure that the envelope sender is always set to the From: address. This is highly useful on a web hosting server where most people just install whatever programs they find and they don't use the -f or Return-path: headers to set the envelope sender. When they do this and a bounce occurs, the webmaster doesn't get the bounce mail, so they don't know that there is a problem. To fix this use:

*@*.your.domain  ${sg{$h_from:}{^.*<(.*)>}{\$1}}  Ffrs

This causes [[email protected]](mailto:[email protected]) to be replaced with their From: header. And if they've entered a full From address, then it will strip the e-mail from "User name" <user@domain>. This helps in tracking down the mail a lot, and makes sure that customer's get their bounces.

Unfortunately the example above doesn't work if your mail or rcpt ACL has a "verify = sender" line, because that causes the return-path rewrite to happen before the mail headers (and thus the From: address) are available. A solution is to rewrite the envelope-from (return-path) from the smtp transport. An example:

remote_smtp:
  driver = smtp
  return_path = ${if eq{$return_path}{[email protected]}{${address:$h_from:}}fail}

⚠️ **GitHub.com Fallback** ⚠️