I already wrote about sending mails with ssmtp, a simple alternative to sendmail. But since I got a few questions (and I tend to forget myself) how to use ssmtp’s revaliases
-file, here is a short reminder:
/etc/revaliases
, allows you to map a local user to a specific ‘From:’ address on outbound mail and to route that mail through a specific mailhub. But it will not rewrite the ‘To:’ address according to the local user who should receive the mail.
Usually, you would add aliases to /etc/aliases
to ensure that a local user (receiving a mail) is mapped to a valid eMail address. But as the documentation clearly says (if you actually read it), ssmtp does not use /etc/aliases
.
The solution turns out to be letting mail
handle the alias – which is done by configuring aliases in /etc/mail.rc
set ask askcc append dot save crt ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To alias root root<yourname@domain.com> alias localuser localuser<yourname@domain.com>
You can test it with with:
# echo test | mail -s "testing ssmtp" localuser
The mail will actually be delivered to yourname@domain.com (since ‘localuser’ is mapped to this address in /etc/mail.rc
).
Enjoy!
Resources:
http://www.linux.com/archive/feature/132006
http://greybeardedgeek.net/?p=17
Pingback: sSMTP aliases | Записки Плюшевого Крыса
Pingback: Using ssmtp on CentOS « mbrownnyc
This is great little tutorial and helped me out no-end. Good work!
exactly what i was looking for. I still cant get mine to work, the TO: emails are still going to my hostname eg localhost@ubuntupc
how do you get the mail.rc file? do you just create it yourself and ssmtp automatically recognises it ?
@john
ssmtp doesn’t care about the mail.rc afaik, but if you send your eMail through “mail” (see the example above) it uses the alias set in mail.rc with the MTA you set up.
Note that /bin/mail is just a link to /bin/mailx on Fedora.
Fantastic – been looking for this for ages
@john
You need to use the bsd-mailx package to provide the mail command.
This fixed it for me.
thank you for this post, has helped me too..
Do you need an mta to get local mail, or will mail do?
@Frank
No, you’d need an MTA to send the mails to a remote server. You could use a full-featured MTA like sendmail or a very simple program like ssmtp.
great advise, thanks a lot – been looking for this for a long while. feeling very much safer now in case my RAID crashed as mdadm send mail-notifications by default.
if anybody feels like your system is ignoring the information you store within “/etc/mailrc” try editing “etc/nail.rc” – referring to: http://www.linuxquestions.org/questions/linux-newbie-8/mailx-doesn%27t-read-from-etc-mail-rc-4175526177/
@Micha
Thanks a bunch for the link! That’s really helpful.
Nice posting. Thanks.
i am able to use ssmtp to send email (from cron ) to a mail address somewhere on the internet.
Now I want to receive the mail from cron in my local mail folder, I think it is /var/mail/plato on Debian, and read it with a mail client like mutt.
So far I did not succeed. Any ideas on how to accomplish that?
Thanks,
Plato
Pingback: ssmtp sends To ‘root’ instead To my email – Internet and Tecnnology Answers for Geeks
Pingback: ssmtp root alias doesn’t work – Internet and Tecnnology Answers for Geeks
Thank you so much for explaining the aliasing with mail! Was banging my head onto the table as to why the aliases file is not respected.