Is it possible to set up system mail on a linux box to be sent via a different smtp server - maybe even with authentication? If so, how do I do this?

If that's unclear, let give an example. If I'm at the command line and type.

cat body.txt | mail -s "just a test"

is it possible to have that be sent via an external SMTP server, like G-mail ?

I'm not looking for "a way to send mail from gmail from the command line" but rather an option to configure the entire system to use a specific smtp server, or possibly one account on an smtp server (maybe overriding the from address).

Best Answer

I found sSMTP very simple to use.

In Debian based systems.

apt-get install ssmtp

Then edit the configuration file in /etc/ssmtp/ssmtp.conf

A sample configuration for your gmail account for sending e-mails

# root is the person who gets all mail for userids < 1000

# Here is the gmail configuration (or change it to your private smtp server)

Note : Make sure the "mail" command is present in your system. mailutils package should provide this one in Debian based systems.

Update : There are people (and bug reports for different Linux distributions) reporting that sSMTP will not accept passwords with a 'space' or '#' character. If sSMTP is not working for you, this may be the case.