10

We have a working exim setup at a site, where users can send and receive mails. We are trying to setup a server to send some warnings and errors using email to an address that is outside the local network.

The problem is:

The program that sends the mails sends them using the username it runs under and the local hostname of the server. This cause the mails to have a sender of format: myapp@myserver.mydomain. Exim sends these mails to the ISP's SMTP server, which rejects the mails as they have an illegal or unverifiable sender (the internal address).

I'm thinking I should configure exim to rewrite the sender when:

  • sender's domain is on the local network
  • receiver's domain is outside the local network

I tried setting some kind of rewriting in the exim config, but did not manage to get it to work. I'd show what I have tried, but I ran out of time on the last visit to the site, and had to revert to the original version losing all the changes I tried.

Esa Varemo
  • 551
  • 3
  • 8
  • 21

3 Answers3

12

The file /etc/email-addresses should handle the problem. This is a standard part of the Exim distribution. You will need to configure one record for each local user sending email.

Try a line to /etc/email-addresses like:

 myapp:   donotreply@example.com

On your MX server add an alias like:

 donotreply:    :blackhole:

Use a Reply-to: header to allow the recipient to reply to the message.

The file /etc/email-addresses is used the following rewrite code, which should be at the start of the rewrite section of the configuration file.

*@+local_domains "${lookup{${local_part}}lsearch{/etc/email-addresses}\
                  {$value}fail}" Ffrs
BillThor
  • 27,354
  • 3
  • 35
  • 69
  • `/etc/email-addresses` does not exist on my server. Can I just create it, or does that indicate that something is missing? – Esa Varemo Oct 26 '13 at 17:51
  • @EsaVaremo Grep your configuration file for `email-addresses`, or check your configuration file for the rewrite section. It is possible this was not configured in your distribution. – BillThor Oct 26 '13 at 17:57
  • I tried `grep`, `locate` and looked for a few `man`-pages, but did not find anything. Should the file be defined in `exim.conf`? – Esa Varemo Oct 26 '13 at 18:24
  • @EsaVaremo The line at the end of my response should be in the rewrite section of `exim.conf`. If it is missing add it. Make sure the variable `local_domains` includes your domain. – BillThor Oct 26 '13 at 23:31
  • I noticed your edit a while after I had made my last comment. For whatever reason I did not get that to work though, so I went with the other answer, as I was running out of time. I do not doubt that this is right, I propably just had mistyped/configured something... – Esa Varemo Oct 27 '13 at 09:30
  • @EsaVaremo The other answer works for one userid at a time and requires a configuration reload to make changes. The /etc/email-addresses solution works on multiple user ids, and does not require restarts when making changes. Either should be sufficient for your case. – BillThor Oct 28 '13 at 11:37
  • I want to do this but at SMTP time (as described in @Kondybas' answer); how do i express `*@+local_domains` as a regular expression? – ShadSterling Sep 04 '19 at 01:47
11
begin rewrite
myapp@myserver.mydomain   legal.user@myserver.mydomain   SFfrs

The flags have the following meanings:

  1. S - Do all rewriting at SMTP time. This means that all of the following flags are done immediately as the data they apply to is coming in, not delayed until later.
  2. F - Rewrite the envelope from field.
  3. f - Rewrite the From: header field.
  4. r - Rewrite the Reply-To: header field.
  5. s - Rewrite the Sender-To: header field.

Read Chapter 31 of the Exim Specification for more detail on message rewriting

Todd Lyons
  • 2,006
  • 16
  • 12
Kondybas
  • 6,864
  • 2
  • 19
  • 24
1

/etc/email-addresses is handy when you only need to associate one email address per username. However if your user needs to send emails with multiple addresses, you will have to modify /etc/email-addresses each time, and you will inevitably end up using the wrong address.

Another approach is to send the email using the exim4 command and its -f option :

$ cat email|/usr/sbin/exim4 -f myapp@example.com recipient@example.com

Note that for the -f option to work, you need either your user to be in exim's trusted users or exim to accept him as an allowed untrusted sender.

In my case the latter was default, thanks to this wildcard in /etc/exim4/conf.d/main/02_exim4-config_options :

untrusted_set_sender = *

The other solution is to add the following line in /etc/exim4/conf.d/main/00_local_settings (assuming exim's split configuration, and create it if it doesn't exist already) :

MAIN_TRUSTED_USERS = yourusername

Both options need a reload of exim's configuration. Under Debian :

# dpkg-reconfigure exim4-config