RiccardOne
Posts: 2
Joined: Sun Feb 14, 2016 4:55 pm

Mail on Buster

Sun Jun 30, 2019 7:34 am

On a fresh installed Buster OS on a Raspi zero I can't send mail, I get this error:
mail: cannot send message: Process exited with a non-zero status

On a Raspi zero with Stretch and the same mail configuration the mail works.
Anybody has the same issue? suggestions?
Riccardo

Here is my setup:
Loading the packages
sudo apt-get install ssmtp
sudo apt-get install mailutils mpack

Setting up the defaults for SSMTP
sudo nano /etc/ssmtp/ssmtp.conf

1. Now edit the fields:
root=postmaster
mailhub=smtp.gmail.com:587
hostname=rpi0c
AuthUser=[email protected]
AuthPass=userpass
FromLineOverride=YES
UseSTARTTLS=YES

Using Email Now
sudo reboot
echo "sample text" | mail -s "Subject" [email protected]

pcmanbob
Posts: 6934
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Mail on Buster

Sun Jun 30, 2019 9:07 am

Yes SSMTP does not seem to work on buster, but I can send email using the same gmail credentials using smtplib in a python program, So there must be an incomparability with SSMTP or one of it dependants in buster, but I have no idea what.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

HMo
Posts: 1
Joined: Sun Jun 30, 2019 1:36 pm

Re: Mail on Buster

Sun Jun 30, 2019 1:44 pm

I have made the same observations with Debian / Raspbian – Buster and ssmtp.

Then, I have followed this Wiki Ubuntu about msmtp
https://doc.ubuntu-fr.org/msmtp and
https://doc.ubuntu-fr.org/tutoriel/comm ... e_commande.

Reboot and tested with mail like this :

echo 'message' | mail [email protected]

I could reuse my programs without changes.

harisb
Posts: 1
Joined: Fri Jul 05, 2019 3:40 pm

Re: Mail on Buster

Fri Jul 05, 2019 3:59 pm

Hi,
Below are my own observations, in case they can help.

I added DEBUG=YES in ssmtp.conf and examined the differences in /var/etc/mail.log
between two identically configured raspberry boxes. In both boxes ssmtp was configured
to send email via gmail.

- Box A with raspberry stretch (ssmtp working ok)
- Box B with raspberry buster (ssmtp not working)

I observed that after trying to send an email from both boxes,
in Box A (the mail went through ok) I had the following log line in mail.log:
SSL connection using RSA_AES_128_CBC_SHA1

In Box B (sending the mail failed) the above log line had been replaced with:
SSL connection using ECDHE_RSA_AES_256_GCM_SHA384

So, it seams that, in buster, ssmpt tries to use a different ciffer.

pcmanbob
Posts: 6934
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Mail on Buster

Sun Jul 07, 2019 11:26 am

HMo wrote:
Sun Jun 30, 2019 1:44 pm

Then, I have followed this Wiki Ubuntu about msmtp
https://doc.ubuntu-fr.org/msmtp and
https://doc.ubuntu-fr.org/tutoriel/comm ... e_commande.
Thanks HMo for the links
got my pi email working on buster , with a bit of help from google translate.
:D :D :D :D :D
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Mail on Buster

Wed Jul 10, 2019 1:03 pm

Just to follow-up on the previous posts, ssmtp is deprecated on Buster, it is no longer maintained.
(typical experience with a major system change..., sigh!)

The more modern and supported alternative is msmtp.

You can install that package with:

Code: Select all

sudo apt-get install msmtp msmtp-mta
The configuration file is located here : /etc/msmtprc
Strangely enough, it is empty with no clues, which is different from the good old ssmtp.conf file.
However, there is a very large description with details if you use

Code: Select all

man msmtp
For gmail accounts, these are the specific elements you should put into /etc/msmtprc:

Code: Select all

# Generics
defaults
auth           on
tls            on
# following is different from ssmtp:
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# user specific log location, otherwise use /var/log/msmtp.log, however, 
# this will create an access violation if you are user pi, and have not changes the access rights
logfile        ~/.msmtp.log

# Gmail specifics
account        gmail
host           smtp.gmail.com
port           587

from          [email protected]
user           [email protected]
password       your-gmail-account-password

# Default
account default : gmail
You can test this with:

Code: Select all

echo 'your message' | msmtp [email protected]
I have not yet found a way to set the subject, there is no -s flag either.

However, if you also install mailutils:

Code: Select all

sudo apt-get install mailutils
Then these two work again:

Code: Select all

echo 'message' | mail -s "raspi-buster" [email protected]
echo 'message' | sendmail [email protected]
Unfortunately, my watchdog setup nor cron get the mail out. From the error message in /var/log/mail.err it seems that there is an incompatibility with this setup, and the previously established mail setup.

Hopefully somebody that is more adept can help out to get this fixed.


Hope this helps to get mail going on buster.

Enjoy!
Last edited by paulv on Fri Jul 12, 2019 1:15 pm, edited 3 times in total.

pcmanbob
Posts: 6934
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Mail on Buster

Wed Jul 10, 2019 1:15 pm

You can use both mailutils and mpack with msmtp just as you did with ssmtp.

So any scripts that you have used before with ssmtp, mailutils or mpack will work just the same using msmtp, mailutils or mpack
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Mail on Buster

Wed Jul 10, 2019 2:46 pm

pcmanbob,

Did you try to get mails out from cron or watchdog?

pcmanbob
Posts: 6934
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Mail on Buster

Wed Jul 10, 2019 2:59 pm

I have several pi's sending emails using cron and also had error messages from cron, if you set up the mailto line in cron, seeing as I am using mail or mpack to send mail from cron I don't see why it should not work with msmtp in exactly the same way.

I would normally just write a short bash script to send the email with what ever information is required
( for example the current IP address of the pi ) and then just call that using cron,

not forgetting that cron runs early in the boot process so if sending email at boot you need to add a delay before trying to send the email to allow networking to be up.

I have never used watchdog so can't comment on that.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

epoch1970
Posts: 3666
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Mail on Buster

Thu Jul 11, 2019 8:12 pm

In case it helps. This comes from a Jessie machine working in the field with msmtp as mailer.

Code: Select all

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie

$ msmtp --version
msmtp version 1.4.32
Platform: arm-unknown-linux-gnueabihf
TLS/SSL library: GnuTLS
Authentication library: GNU SASL
Supported authentication methods:
plain scram-sha-1 cram-md5 external digest-md5 login ntlm 
IDN support: enabled
NLS: enabled, LOCALEDIR is /usr/share/locale
Keyring support: none
System configuration file name: /etc/msmtprc
User configuration file name: /root/.msmtprc

Copyright (C) 2014 Martin Lambers and others.
...
/etc/aliases: /etc/msmtprc:

Code: Select all

$ cat /etc/msmtprc 
# Accounts will inherit settings from this section
defaults
auth on
tls on
tls_certcheck off
# tls_trust_file  /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log
aliases /etc/aliases

# A first gmail address
account admin_mail
host smtp.gmail.com
port 587
from [email protected]
user [email protected]
# App password for this host
# Defined by user randomuser in their G account prefs
# (login to G and add other machines/apps)
password tokengeneratedbygmailforthisapp

# Add more accounts if you want

# Set a default account
account default : admin_mail
The machine has linux watchdog installed and basically the machine (watchdog) sends at least an email per day. I will post a few bits of possibly relevant config in paulv's thread on watchdog. Nothing much.

HTH
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Mail on Buster

Fri Jul 12, 2019 11:35 am

Epoch1970,

Your help is very much appreciated. Merci bien!

First off, I found that you have to use the TLS method the way I used it above, if I use it without as you have, there is an error generated.

With your other information, I think I found the problem with Buster.
There is no /etc/aliases file.

A default installation on one of my Jessie RPi's produces this:

Code: Select all

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
So on Buster, the system has no idea where to send stuff to.
Oversight or bug?

To test this, I added the above entries to /etc/aliases, and as a last line: To cron I added this:

Code: Select all

MAILTO=root


17 14 * * * /bin/sh /home/pi/whatever
Just set your own time instead of 17 14, and this will trigger an email to be sent by cron coming from [email protected] because /home/pi/whatever does not exist. You could also use BTW, I still can't get the watchdog package to mail, or log...

epoch1970
Posts: 3666
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Mail on Buster

Fri Jul 12, 2019 5:36 pm

paulv wrote:
Fri Jul 12, 2019 11:35 am
So on Buster, the system has no idea where to send stuff to.
Oversight or bug?
I tend to port working recipes from machine to machine until it breaks, my encounter with msmtp occurred many years ago.
If you lookup the list of files provided by packages msmtp or msmtp-mta you can find /usr/sbin/sendmail and newaliases (in msmtp-mta) but a template for /etc/aliases is nowhere to be found.
I don't know which package provides /etc/aliases on Debian, if any. Not sendmail-base, as far as I can see. Perhaps some greybeards made an executive decision...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Daddyfix
Posts: 48
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

Re: Mail on Buster

Sun Aug 11, 2019 11:19 pm

paulv wrote:
Wed Jul 10, 2019 1:03 pm
Just to follow-up on the previous posts, ssmtp is deprecated on Buster, it is no longer maintained.
(typical experience with a major system change..., sigh!)

The more modern and supported alternative is msmtp.

You can install that package with:

Code: Select all

sudo apt-get install msmtp msmtp-mta
The configuration file is located here : /etc/msmtprc
Strangely enough, it is empty with no clues, which is different from the good old ssmtp.conf file.
However, there is a very large description with details if you use

Code: Select all

man msmtp
For gmail accounts, these are the specific elements you should put into /etc/msmtprc:

Code: Select all

# Generics
defaults
auth           on
tls            on
# following is different from ssmtp:
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# user specific log location, otherwise use /var/log/msmtp.log, however, 
# this will create an access violation if you are user pi, and have not changes the access rights
logfile        ~/.msmtp.log

# Gmail specifics
account        gmail
host           smtp.gmail.com
port           587

from          [email protected]
user           [email protected]
password       your-gmail-account-password

# Default
account default : gmail
You can test this with:

Code: Select all

echo 'your message' | msmtp [email protected]
I have not yet found a way to set the subject, there is no -s flag either.

However, if you also install mailutils:

Code: Select all

sudo apt-get install mailutils
Then these two work again:

Code: Select all

echo 'message' | mail -s "raspi-buster" [email protected]
echo 'message' | sendmail [email protected]
Unfortunately, my watchdog setup nor cron get the mail out. From the error message in /var/log/mail.err it seems that there is an incompatibility with this setup, and the previously established mail setup.

Hopefully somebody that is more adept can help out to get this fixed.


Hope this helps to get mail going on buster.

Enjoy!
Thank you. This worked like a charm for me!

Aroa
Posts: 2
Joined: Tue Sep 03, 2019 10:21 am

Re: Mail on Buster

Tue Sep 03, 2019 10:34 am

Hello Im new in this world, I have a rapsberry pi3 with debian y want to send email.
I followed this steps :

Daddyfix wrote:
paulv wrote:
Wed Jul 10, 2019 1:03 pm
Just to follow-up on the previous posts, ssmtp is deprecated on Buster, it is no longer maintained.
(typical experience with a major system change..., sigh!)

The more modern and supported alternative is msmtp.

You can install that package with:

Code: Select all

sudo apt-get install msmtp msmtp-mta
The configuration file is located here : /etc/msmtprc
Strangely enough, it is empty with no clues, which is different from the good old ssmtp.conf file.
However, there is a very large description with details if you use

Code: Select all

man msmtp
For gmail accounts, these are the specific elements you should put into /etc/msmtprc:

Code: Select all

# Generics
defaults
auth           on
tls            on
# following is different from ssmtp:
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# user specific log location, otherwise use /var/log/msmtp.log, however, 
# this will create an access violation if you are user pi, and have not changes the access rights
logfile        ~/.msmtp.log

# Gmail specifics
account        gmail
host           smtp.gmail.com
port           587

from          [email protected]
user           [email protected]
password       your-gmail-account-password

# Default
account default : gmail
You can test this with:

Code: Select all

echo 'your message' | msmtp [email protected]
I have not yet found a way to set the subject, there is no -s flag either.

However, if you also install mailutils:

Code: Select all

sudo apt-get install mailutils
Then these two work again:

Code: Select all

echo 'message' | mail -s "raspi-buster" [email protected]
echo 'message' | sendmail [email protected]
Unfortunately, my watchdog setup nor cron get the mail out. From the error message in /var/log/mail.err it seems that there is an incompatibility with this setup, and the previously established mail setup.

Hopefully somebody that is more adept can help out to get this fixed.


Hope this helps to get mail going on buster.

Enjoy!
Thank you. This worked like a charm for me!


but return to me [email protected]:~ $ sudo echo 'your message' | msmtp [email protected]
msmtp: /home/pi/.msmtprc: contains secrets and therefore must have no more than user read/write permissions

I give the permision with chmon 777 /home/pi/.msmtprc

[email protected]:~ $ ls -l /home/pi/.msmtprc
-rwxrwxrwx 1 pi pi 1378 Sep 2 18:11 /home/pi/.msmtprc


But the problem is still.
Can somebody help me please?
Thank you so much

pcmanbob
Posts: 6934
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Mail on Buster

Tue Sep 03, 2019 1:36 pm

Aroa wrote:
Tue Sep 03, 2019 10:34 am
but return to me [email protected]:~ $ sudo echo 'your message' | msmtp [email protected]
msmtp: /home/pi/.msmtprc: contains secrets and therefore must have no more than user read/write permissions

I give the permision with chmon 777 /home/pi/.msmtprc

[email protected]:~ $ ls -l /home/pi/.msmtprc
-rwxrwxrwx 1 pi pi 1378 Sep 2 18:11 /home/pi/.msmtprc


But the problem is still.
Can somebody help me please?
Thank you so much
Hi.

So first question is why are you using " sudo " to call your send mail line ?

You don't need sudo you can send it as the pi user.

Secondly you are getting the message about user permissions because you should only have one user who can read/write the config file for msmtp, so you should be using chmon 700 /home/pi/.msmtprc so that only the pi user has read/write access to the config file.

As always read the error message it tells you what the problem is " contains secrets and therefore must have no more than user read/write permissions "

If you want msmtp to be usable by all users then you need to put the config file in " /etc " and not " /home/pi/ "
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Aroa
Posts: 2
Joined: Tue Sep 03, 2019 10:21 am

Re: Mail on Buster

Tue Sep 03, 2019 2:55 pm

pcmanbob wrote:
Aroa wrote:
Tue Sep 03, 2019 10:34 am
but return to me [email protected]:~ $ sudo echo 'your message' | msmtp [email protected]
msmtp: /home/pi/.msmtprc: contains secrets and therefore must have no more than user read/write permissions

I give the permision with chmon 777 /home/pi/.msmtprc

[email protected]:~ $ ls -l /home/pi/.msmtprc
-rwxrwxrwx 1 pi pi 1378 Sep 2 18:11 /home/pi/.msmtprc


But the problem is still.
Can somebody help me please?
Thank you so much
Hi.

So first question is why are you using " sudo " to call your send mail line ?

You don't need sudo you can send it as the pi user.

Secondly you are getting the message about user permissions because you should only have one user who can read/write the config file for msmtp, so you should be using chmon 700 /home/pi/.msmtprc so that only the pi user has read/write access to the config file.

As always read the error message it tells you what the problem is " contains secrets and therefore must have no more than user read/write permissions "

If you want msmtp to be usable by all users then you need to put the config file in " /etc " and not " /home/pi/ "

Thank you so much. It is solve
You are right, i didnt need sudo before.
i change chmon 700 /home/pi/.msmtprc and also i move the config file in "/etc"
Everything is working great!!!! Thanks :D :D :D :D :D

Return to “Troubleshooting”