Ratsima
Posts: 70
Joined: Tue Nov 10, 2015 12:13 am
Location: Korat, Thailand
Contact: Website

[Solved] sSMTP: forwarding mail for local users

Fri Feb 05, 2016 7:00 am

I have set up sSMTP using the following well-written guide: http://iqjar.com/jar/sending-emails-fro ... pberry-pi/

It works fine to send mail to addresses with fully qualified domain names such as [email protected]

I would like to configure ssmtp to forward local mail (eg. "root") to an external address.

My ssmtp.conf file contains the following line:
But, if I try to send mail to root, I get this:

Code: Select all

Delivery to the following recipient failed permanently:

    [email protected]

Technical details of permanent failure: 
DNS Error: 29226832 DNS type 'mx' lookup of rasp responded with code NXDOMAIN
Domain name not found: rasp
I tried to use an aliases file but:

Code: Select all

[email protected] /etc/ssmtp $ sudo newaliases
newaliases: Aliases are not used in sSMTP
After doing lots of searching, I see many people with the same problem, but no solution given. In fact, people who have scripts that generate error messages mailed to root were told not how to forward the mail, but, instead, how to stop their scripts from generating it.

Is there no way to get sSMTP to forward local mail?
Last edited by Ratsima on Sun Feb 07, 2016 4:46 am, edited 1 time in total.

Ratsima
Posts: 70
Joined: Tue Nov 10, 2015 12:13 am
Location: Korat, Thailand
Contact: Website

Re: sSMTP: forwarding mail for local users

Sun Feb 07, 2016 4:45 am

The answer is to use mailx instead of mail….

Code: Select all

[email protected] ~ $ sudo apt-get install bsd-mailx
The installation will add a configuration file: /etc/mail.rc

You can add aliases to it as follows:

Code: Select all

[email protected] /etc $ cat 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<[email protected]>
alias pi pi<[email protected]>
alias postmaster postmaster<[email protected]>
Now the following works:

Code: Select all

[email protected] /etc $ mail root
Subject: Hi Root
That's all
Cc: 
[email protected] /etc $ 

Max_G
Posts: 38
Joined: Sat May 28, 2016 8:27 am

Re: [Solved] sSMTP: forwarding mail for local users

Sun Jun 12, 2016 3:56 am

Thank you for your post... exactly what I was looking for.
However, after you make the changes to mail.rc how did you restart the mailx service.

I have installed mailx and made the changes, but I am still getting the same DNS error... not wanting to reboot; how do I restart the mailx service.
Thanks!

Ratsima
Posts: 70
Joined: Tue Nov 10, 2015 12:13 am
Location: Korat, Thailand
Contact: Website

Re: [Solved] sSMTP: forwarding mail for local users

Mon Dec 19, 2016 1:19 am

Max_G wrote:Thank you for your post... exactly what I was looking for.
However, after you make the changes to mail.rc how did you restart the mailx service.

I have installed mailx and made the changes, but I am still getting the same DNS error... not wanting to reboot; how do I restart the mailx service.
Thanks!
Sorry that I didn't see this before.

I'm sure you've solved it by now.

The short answer is that it should work without restarting any service. I just did this again on a new Pi and it works fine without having to restart or reload anything.

sromualdo
Posts: 3
Joined: Tue Feb 07, 2017 5:50 am

Re: [Solved] sSMTP: forwarding mail for local users

Tue Feb 07, 2017 6:05 am

I am new raspberry pi user.
I had the same kind of problem and I got a solution in this way:
I created in /home/pi/bin a very simple bash script named "text".
In this script I added informations about temperature, humidity, date, etc on a file named "text.txt"
Ex.: temperature > text.txt
humidity >> text.txt
date >> text.txt
The last line of the script is
sudo ssmtp [email protected]<text.txt
Another script call the script "text" in this way:
/home/pi/bin/text &
I hope you get success too.
Best regards
sromualdo

Return to “Beginners”