10

I'm using ssmtp for sending email (the setting is below)

Now when i run a cron command or an at command, mail is sent to

michel@mypi

which is username @ machinename

Now ofcourse this is not a valid email address, so i get errors in my gmail saying: can't send email to michel@mypi

How and where should i say that email to the user 'michel' should go to a particular email address?

The setting for ssmtp:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000 # Make this empty to disable rewriting.
root=MYNAME@gmail.com

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:465

# Where will the mail seem to come from?
#rewriteDomain=gmail.com

# The full hostname
hostname=MyPi

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address 
# NO - Use the system generated From: address 
#FromLineOverride=YES 
AuthUser=MYNAME
AuthPass=MYPASS
FromLineOverride=YES
UseTLS=YES
AnFi
  • 1,546
Michel
  • 223
  • How does gmail fit into this description? – tink Mar 25 '13 at 20:08
  • ehm, i'm using the gmail account to send email with ssmtp – Michel Mar 25 '13 at 20:21
  • Ah, the error in my gmail is because I configured ssmtp to send email via gmail (see the config in the question) and for some reason the engine which sends email on behalf of cron uses that setting too, and so when cron sends email to michel@mypi it is sent back to my gmail account saying it can not send email to michel@mypi – Michel Mar 25 '13 at 21:20
  • 2
    @Michel ssmtp doesn't do local mail. If you want local mail and smart host sending, you will want a real MTA such as exim4 or postfix, which can do both. – jordanm Mar 25 '13 at 21:38
  • 1
    @jordanm Yeah, i just noticed 1 minute ago that the MyPi were the mail goes to wasn't the machine name, but the hostname setting from the ssmtp config (which had the same value as my machine name). What ssmtp seems to do is to add the setting in the hostname to the local user name and use that as an email address. I tried exim4 once and i couldn't get it to work, and I'm afraid to reset my mail install just for this issue. Is there a way to workaround this? Say let ssmtp ignore local mail, or don't let cron and at send email? – Michel Mar 25 '13 at 21:45
  • @Michel You can set MAILTO="foo@gmail.com" in your crontab file so that the email goes to an internet accessible address. – jordanm Mar 25 '13 at 21:50
  • Does that also work for the at command? – Michel Mar 25 '13 at 21:51
  • Oh, i just tried: it doesn't get picked up by the at command, is there a way? – Michel Mar 25 '13 at 22:05
  • @jordanm: the MAILTO does work for the cron, great! – Michel Mar 26 '13 at 08:39
  • ssmtp does NOT verify the SSL/TLS certificate of the remote server on the current debian, ubuntu and redhat releases and also does NOT verify the hostname of the certificate. This is a major issue, as this effectively renders the encryption useless and your password is being transmitted alike to being plaintext and anyone can sniff it. ssmtp has had no active development since atleast 2009. So, if you care about the security of the email account you use for your servers outgoing emails, do NOT use ssmtp, but postfix (or something else) instead: http://unix.stackexchange.com/a/118101/72087 – Zulakis Feb 24 '16 at 10:14
  • Check out this one for the simplest answer: https://unix.stackexchange.com/questions/363814/simplest-way-to-send-one-line-mail-out-via-command-line – SDsolar May 09 '17 at 02:22

3 Answers3

12

Sorry to raise the dead, but I stumbled across this via Google and have just solved it: the /etc/ssmtp/revaliases is only the aliases for the FROM: addresses.

Aliases for TO: addresses would normally need to be set in /etc/aliases, but SSMTP doesn't read this! Instead, you need to edit /etc/mail.rc and add a line such as

alias root root<yourname@youremail.com>

See http://possiblelossofprecision.net/?p=591 for more info.

UPDATE 2019-05-07 - According to comments below, the later versions of the package that are now in EPEL (if you're on RedHat family distros) now do read the /etc/aliases file, so check your version!

shearn89
  • 462
  • 1
    No need to apologise - it's great that you post a solution, it will help anyone else who tries to use this and runs into the same problem! – Jenny D Apr 14 '14 at 14:02
  • 1
    This was it! I think most of the other guides that mention revaliases work because the uid being sent to is <1000 and the root address just collects all of them. – psp Dec 20 '15 at 16:37
  • you are my hero – Greg Flynn Jan 25 '17 at 21:31
  • 1
    Just a note that ssmtp version 2.64 which is in the EPEL repo for CentOS 7 does in fact use /etc/aliases instead of /etc/mail.rc. – sdragnev Mar 26 '19 at 14:01
1

Try this:

Simplest way to send one-line mail out via command line using gmail?

Excerpt:

root=rpi3abc@gmail
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=rpi3abc@gmail.com
AuthPass=testing123
UseTLS=YES
SDsolar
  • 1,849
1

Use the file /etc/ssmtp/revaliases to enter your aliases, e.g.

michel:username@gmail.com:smtp.gmail.com:465
Jenny D
  • 13,172
  • that doesn't seem to work. When i send mail to michel it does not work. – Michel Mar 26 '13 at 08:39
  • What does "doesn't work" mean? What do the logs say? – Jenny D Mar 26 '13 at 08:40
  • I get the same error in my mail. What i described earlier (What ssmtp seems to do is to add the setting in the hostname to the local user name and use that as an email address.) still happens, the revaliases file isn't used. Isn't it btw strange that I have to specify a email server for an alias? – Michel Mar 26 '13 at 08:46