Howto set up ssmtp to send through a Gmail account
Some of the steps here might seem strange at first, but the rationale is put
in footnotes that should hopefully explain why.
First create a spare account on gmail which you will only use for
sending email. For instance, if your normal account is [email protected]
,
create an account [email protected]
with a newly created password
which you only will use for this account [1].
Set up the new account to forward all email to the normal account [2]
and under account settings you should add all other email adresses you
use [3].
Then install ssmtp (On Debian: aptitude install ssmtp
) and edit ssmtp's configuration file /etc/ssmtp/ssmtp.conf
:
[email protected]
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=user.noreply
AuthPass=passwdusedonlyforthisaccount
FromLineOverride=YES
and configure the local mail delivery by editing /etc/ssmtp/revaliases
assuming that your local login is localuser
:
root:[email protected]:smtp.gmail.com:587
localuser:[email protected]:smtp.gmail.com:587
Make sure the two configuration files are readable to all users who
should be able to send email [4].
Test the setup by e.g. mailx
(On Debian: aptitude install bsd-mailx
):
echo 'testing, one, two' | mailx -s 'test 1' [email protected]
Hope this helps.
[1] The new gmail user name and password will be visible to everyone who
can log onto your machine, so you do not want this account to be
critical in any way, meaning you can close it down immediately if
someone should get access to it.
[2] If some email you sent bounces back to you, you might want to know
about it, and there actually exists people who will happily reply to an
email from johnsmith.noreply
.
[3] Gmail will rewrite the From
header on the email if it does not recognise the address.
[4] Ssmtp runs as the local user who sends the email, so that user needs
read access to the configuration files.