4

On my Raspbian server, I wish to have local *nix mail delivered locally, as well as to an external address. /home/pi/.forward contains pi,[email protected]. I've run sudo dpkg-reconfigure exim4-config with the following options.

  • mail sent by smarthost; received via SMTP or fetchmail.
  • System mail name: raspberrypi.
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1
  • Other destinations for which mail is accepted: none.
  • Machines to relay mail for: none.
  • IP address or host name of the outgoing smarthost: smtp.bar.com:465
  • Hide local mail name in outgoing mail? Yes.
  • Visible domain name for local users: bar.com
  • Keep number of DNS-queries minimal (Dial-on-Demand): No.
  • mbox format in /var/mail/
  • Split configuration into small files? No.

Note that I've set the apparent sending domain as bar.com, as I suspect my SMTP server requires that. I've then added the associated credentials in /etc/exim4/passwd.client, i.e. smtp.bar.com:[email protected]:PASSWORD. Then I've run sudo update-exim4.conf; sudo invoke-rc.d exim4 restart; sudo exim4.

Testing, if I send mail to an external address, it works fine.

echo -e "Test body" | mail -s 'Subject' [email protected]

I receive the mail at [email protected], and the sender is [email protected].

However, if I send it to the local address, it only goes to the local address.

echo -e "Test body" | mail -s 'Subject' pi

In this case, the sender is pi@raspberrypi, which probably makes the SMTP server reject it. How can I send mail to both the local server and the external?

Sparhawk
  • 19,561
  • 18
  • 86
  • 152
  • If you're using postfix on Pi: http://blog.bobbyallen.me/2013/02/03/how-to-redirect-local-root-mail-to-an-external-email-address-on-linux/ – slm Oct 27 '14 at 11:44
  • @slm I'm not sure if I'm using postfix, but that link is for forwarding to an email address without keeping a local copy, if I read it correctly. (and similar to my first link) – Sparhawk Oct 27 '14 at 11:45
  • I use a similar method and it can be made to retain a local copy and forward. See my A. – slm Oct 27 '14 at 11:46
  • With Debian 8 and a hosting provider, I'd like to add: If you want to use TLS, it's not required to directly specify a port; and it mey even fail. `exim4` does not support immediate TLS on any port. So if the above does not work for you, try to omit the port and look for the `X=` information in `/var/log/exim4/mainlog`. If it mentions `TLS`, the communication was encrypted. – Run CMD Nov 10 '15 at 08:39

1 Answers1

4

With most mailers you can do something like this in the /etc/aliases file.

joe: joe, [email protected]

After making changes to this file you typically have to run the command, newaliases.

References

slm
  • 363,520
  • 117
  • 767
  • 871