4

I know that you can change the from address in *nix mail by specifying command-line options. However, is there a way to set it globally, so that it is respected by forwarding?

I tried modifying the $REPLYTO environment variable, but this did not help.

Background

I have set up my Raspbian mail to forward by configuring /etc/aliases. However, for external email recipients, the sender is pi@bar.com, where pi is the Linux login name. I want to find a way to specify the username manually, to match my email account, foo@bar.com.

My exim4 configuration is specified here. N.B. there is an option to specify the sender domain ("Visible domain name for local users: bar.com"), but not a way to specify the username for each account.

Sparhawk
  • 19,941
  • Could you do this on your mail client? –  Oct 28 '14 at 18:22
  • @barrycarter I'm not sure what you mean. There's no mail client involved, really. – Sparhawk Oct 28 '14 at 23:31
  • How are you sending email then? Even if you're using /usr/ucb/Mail, that's still a client. These are emails going outbound from your server to someone else, right? –  Oct 29 '14 at 00:13
  • Ah okay. I guess we're interpreting the word "client" differently. I'm not sure what /usr/ucb/Mail is, but I think I'm using exim4. Emails are sent by the server internally to local mail, and also forwarded externally, as per the second link. – Sparhawk Oct 29 '14 at 00:18

1 Answers1

3

It sounds like you want Exim's address rewriting.

In the rewriting section of your Exim config file, you will probably want something along the lines of this:

pi@bar.com foo@bar.com Ffr

You may need to adjust the flags ("Ffr") to the specific behavior you want.

More generally, see: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html

Raspbian

Specifically, in Raspbian, edit /etc/exim4/exim4.conf.template, adding the following in the REWRITE CONFIGURATION section.

pi@bar.com foo@bar.com Ffr

If you prefer all outgoing email to be from foo@bar.com, regardless of original sender, use this line instead.

* foo@bar.com Ffr

Next, run sudo update-exim4.conf, then check to make sure it worked with exim -brw pi@bar.com. This should print out a list of the headers after the rewrite rules have been applied.

user9999999
  • 772
  • 4
  • 20
  • Works perfectly. Thank you! I've taken the liberty of adding information specific to Raspbian, as per the original question. Cheers! – Sparhawk May 06 '16 at 10:29
  • Hmmm… is there a way to also change the "Real name" of the sender? At the moment, I'm getting automated emails from root <foo@bar.com>. I'd like to change the root part. – Sparhawk May 09 '16 at 12:02
  • Thanks for that. I'll try it when I have a moment. Thanks again for the great answer! – Sparhawk May 12 '16 at 02:31