10

We use Exim on our servers to send emails only from local automated users, as root, cron, etc.

We have to specify every possible users into /etc/email-addresses. For example:

root: alert@example.com  
cron: alert@example.com  
backup: alert@example.com` 

This allow us to receive every email generated.

The problem is when we add a user for whatever reason (for example when we add a package, some add a user), we can forget to add this user to /etc/email-addresses. Most of the time it's not a problem, but this is not clean. And the overall method is not clean.
We'd like to configure Exim to send every emails with the same source address. i.e. every sent email comes from alert@example.com

One way could be to use a wildcard or a regular expression into /etc/email-addresses but this is not supported.
I don't currently understand Exim enought to figure out how to modify this in a way or another.
Ideally, Exim should look into /etc/email-addresses first, and if no match it use the predefined address. But this is very secondary.

There are two places where this address is used:
1. when Exim send the FROM: command to the smtp server
2. inside the header

edit:
The rewrite section is the original one from Debian

begin rewrite  
.ifndef NO_EAA_REWRITE_REWRITE  
*@+local_domains "${lookup{${local_part}}lsearch{/etc/email-addresses} \  
{$value}fail}" Ffrs  
*@ETC_MAILNAME "${lookup{${local_part}}lsearch{/etc/email-addresses} \
{$value}fail}" Ffrs  
.endif
Zypher
  • 36,995
  • 5
  • 52
  • 95
Gregory MOUSSAT
  • 1,737
  • 2
  • 25
  • 48

2 Answers2

10

A much better approach:

Modify the rewrite section: change lsearch by wildlsearch (two lines have to be changed). This allow to use wildcards and regular expression into /etc/email-addresses

So the /etc/email-addresses can contain this kind of thing:
root: root@example.com
*: alert@example.com

The file is processed from top to bottom. So if an email is sent to root, it is really sent to root@example.com. And every other emails are sent to alert@example.com

Gregory MOUSSAT
  • 1,737
  • 2
  • 25
  • 48
  • 2
    On Ubuntu, I had to make the `wildlsearch` change in /etc/exim4/exim4.conf.template, run `sudo update-exim4.conf` and `sudo /etc/init.d/exim4 restart` – Andy Dec 11 '14 at 19:44
  • If your config files are split then you have to make the change in `/etc/exim4/conf.d/rewrite/31_exim4-config_rewriting`. – mkurz Aug 09 '18 at 15:30
2

Somewhere after begin rewrite (and before the next section starting with a begin) add this:
* name@domain.tld Ffrs

The wildcard stand for every addresses
name@domain.tld is the address you want
Ffrs stand for:
F rewrite the envelope From field
f rewrite the From: header
r rewrite the Reply-To: header
s rewrite the Sender: header

This will replace EVERY sender address.

Bertrand SCHITS
  • 2,902
  • 1
  • 12
  • 15