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.


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.

  • Could you do this on your mail client?
    – user2267
    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?
    – user2267
    Oct 29 '14 at 0: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 0:18

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


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.

  • Works perfectly. Thank you! I've taken the liberty of adding information specific to Raspbian, as per the original question. Cheers!
    – Sparhawk
    May 6 '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 9 '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 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.