Page 1 of 1

Email - Sending Logs.

Posted: Thu 19 Aug 2021 2:33 am
by Phil23
Hi All,

Hoping I someone in the Linux world can put me out of my misery.
I want to send emails of logs from my new remote site.

Thought it would be simple from all the reading I did before deciding which direction to take, but I'm beating my head against the wall.
My hosting provider even blacklisted me after a few failed attempts.
This has been my main point of reference, https://www.raspberrypi.org/forums/view ... p?t=189008

To date, have installed ssmtp, mailutils & mpack.

My test account has been setup on my host as test@inverellit.com
This is their guide:-
Mailconfig.JPG
What I've put in /etc/ssmtp/ssmtp.conf is this:-
(Noting that I've read that I should not use special characters in the password. Ei "#" obviously).

Code: Select all

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=test@inverellit.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=mail.inverellit.com:587

AuthUser=test@inverellit.com
AuthPass=password here
UseTLS=Yes
UseSTARTTLS=Yes

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

# The full hostname
hostname=rPi-4-2

# 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
When I try & test it in a shell with
pi@rPi-4-2:~ $ echo "Hello world email body" | mail -s "Test Subject" myname@mydomain.com.au

It just times out & returns,
mail: cannot send message: Process exited with a non-zero status

/var/log/mail.log has this

Code: Select all

Aug 18 16:15:13 rPi-4-2 sSMTP[16590]: Creating SSL connection to host
Aug 18 16:15:13 rPi-4-2 sSMTP[16590]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Aug 18 16:15:15 rPi-4-2 sSMTP[16590]: Authorization failed (535 Incorrect authentication data)
Aug 18 16:20:44 rPi-4-2 sSMTP[17272]: Authorization failed (535 Incorrect authentication data)
Aug 18 16:27:54 rPi-4-2 sSMTP[18153]: Creating SSL connection to host
Aug 18 16:27:54 rPi-4-2 sSMTP[18153]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Aug 18 16:27:56 rPi-4-2 sSMTP[18153]: Authorization failed (535 Incorrect authentication data)
Aug 18 16:34:50 rPi-4-2 sSMTP[19021]: Authorization failed (535 Incorrect authentication data)
Aug 18 19:28:37 rPi-4-2 sSMTP[7903]: Authorization failed (535 Incorrect authentication data)
Tried Port 465 this morning & got this

Code: Select all

Aug 19 11:44:42 rPi-4-2 sSMTP[30004]: Creating SSL connection to host
Aug 19 11:47:27 rPi-4-2 sSMTP[30004]: Invalid response SMTP Server (STARTTLS)
Aug 19 11:47:27 rPi-4-2 sSMTP[30004]: Cannot open mail.inverellit.com:465
Tried the TLS settings off last night as well, but after those failed attempts 16:15 to 16:34, they Blacklisted my IP
& then it was an hour on support to get access to my services again, so am now a bit gun shy on testing too hard.

Tested it in Outlook like this & it works just fine.
Mailconfig2.JPG
Any solution would be greatly appreciated,

Thanks

Phil.

Re: Email - Sending Logs.

Posted: Thu 19 Aug 2021 4:25 am
by freddie
In ssmtp.conf you should have the following for SSL connection:

Code: Select all

mailhub=mail.inverellit.com:465
UseTLS=Yes
UseSTARTTLS=No
For non-TLS:

Code: Select all

mailhub=mail.inverellit.com:587
UseTLS=No
UseSTARTTLS=No
Note that your provider MAY require UseSTARTTLS=Yes for the non-SSL connection.

Are you running your test from your remote host?

Re: Email - Sending Logs.

Posted: Fri 20 Aug 2021 3:35 am
by Phil23
At this stage I've only been testing on my local pi. My Local ISP.

Can also add that about a week ago one of my Win7/Office 2010 PC's started getting refused connections on Port 465, and I was advised to use port 587 as detailed above in the Outlook screen cap.

Just tried the 2nd config you suggest & error returned is this....

Code: Select all

Aug 20 13:31:58 rPi-4-2 sSMTP[24569]: Authorization failed (535 Incorrect authentication data)

Re: Email - Sending Logs.

Posted: Fri 20 Aug 2021 5:04 am
by freddie
Phil23 wrote: Fri 20 Aug 2021 3:35 amJust tried the 2nd config you suggest & error returned is this....

Code: Select all

Aug 20 13:31:58 rPi-4-2 sSMTP[24569]: Authorization failed (535 Incorrect authentication data)
To me it looks as if you are making the connection to the SMTP server but your username and/or password isn't correct. Could be either a genuine typo, or you are not supplying username/password, or even you are supplying username/password and they are not needed (unlikely).

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 4:38 am
by Phil23
Quadrupple checked the Password etc....
It's correct.

Lots of hits here but no answer yet.

https://www.google.com/search?q=%22ssmt ... ation+data

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 5:22 am
by Phil23
Phil23 wrote: Sat 21 Aug 2021 4:38 am Quadrupple checked the Password etc....
It's correct.
You know those issues that go on & on & you double check but a mind block make you see what you want to see...
I've had one of those moments. the "u" was clearly missing in the plain view text in the config file.... :bash: :bash: :bash: :bash: :bash: :bash:

So one step closer, but now getting a 550 error from the test echo "Hello world email body" | mail -s "Test Subject" me@mydomain.com.au

Code: Select all

Aug 21 15:06:40 rPi-4-2 sSMTP[17335]: RCPT TO:<me@mydomain.com.au> (550 Sender verify failed)
So the Sender must not be being past on?
Sender is test@mydomain.com

(Note I do hold both mydomain.com & mydomain.com.au).

Not quite clear on this bit of the config.

Code: Select all

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=test@mydomain.com
Is root referring to the root user? & should I instead have that line as pi as I am attempting to run test this under the pi user.

Thanks.

Phil.

PS Have also tried the suggestions of adding this to /etc/ssmtp/revaliases

Code: Select all

root:test@mydomain.com:mail.mydomain.com:587
but also not sure I I should use pi there as well.

Just paranoid about being blacklisted again so being a bit cautious.

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 5:42 am
by Phil23
And you get an error:

mail: cannot send message: Process exited with a non-zero status

If you're on Buster, then ssmtp is no longer maintained and doesn't work anymore.

Instead, uninstall it

Code: Select all

sudo apt-get --purge remove ssmtp
and replace it with msmtp

https://www.raspberrypi.org/forums/view ... p?t=210227

:groan:

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 6:26 am
by Phil23
Last ditch attempt. And it Worked!

Changed this in /etc/ssmtp/revaliases before removing ssmtp.
Added pi

Code: Select all

# sSMTP aliases
# 
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root:test@inverellit.com:mail.inverellit.com:587
pi:test@inverellit.com:mail.inverellit.com:587
So now this works & sends me a log file via email.

Code: Select all

#!/bin/bash

# Backup Log Email Script 20 July 2021

# put email address in line below
email_addresses1="me@inverellit.com.au"
email_addresses2="me@gmail.com"

current_time=$(date "+%Y.%m.%d")

mpack -s "Log File Attached" /home/pi/backup_log.txt $email_addresses1
#mpack -s "Log File Attached" /home/pi/backup_log.txt $email_addresses2
Hope this long rant can be of help to others who would like to receive log files in the same manner.

Cheers

Phil.

(Only catch now is that Outlook opens the logs in Notepad which doesn't handle the Linux lack of <Cr>'s) :oops:

Anyone else having GREAT fun in Lock-Down?

Edit:-
Actually the Linux text file displays fine in Outlooks "Preview" and also in gmail.

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 10:23 am
by HansR
Thnx

Re: Email - Sending Logs.

Posted: Sat 21 Aug 2021 10:32 pm
by Phil23
$30,000 question now is do I now replicate the working solution from my test pi to the two active CMX pi's,

Or do I abandon sSMTP & start afresh for some more challenges & try the same but using the updated mSMTP.

:roll:

Re: Email - Sending Logs.

Posted: Sun 22 Aug 2021 2:37 am
by Phil23
For the record, will add a link to another post to the thread that discusses the issues with sSSTP Vs mSMTP and offers more current advice.

Someone states that it is related to the Cipher being used:-

Code: Select all

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.
So seems that the reason I have it working is I'm using an non-SSL/TLS connection.

https://www.raspberrypi.org/forums/view ... 52fd5c2b09

Cheers.

Re: Email - Sending Logs.

Posted: Sun 22 Aug 2021 6:22 am
by HansR
Well, seems kind of idiotic that is is so difficult to send an email from an RPi. But anyway, that's life apparently.
Thanks for that last link which sheds more light on the situation and has kind of step by step instruction. I doubt I will make the effort at the moment but you never know.
It should not be too hard for the Raspbian guys to make an entry in raspi-config to say : want mail? yes/no.

Re: Email - Sending Logs.

Posted: Sun 22 Aug 2021 10:33 am
by Phil23
HansR wrote: Sun 22 Aug 2021 6:22 am Well, seems kind of idiotic that is is so difficult to send an email from an RPi.
Well sorted now that I've pulled all the advice posts into their correct context in the terms of Date/Versions etc....
Once the issues were known I had the Remote pi hitting you with the email in short course as received.

I do like receiving emails from my devices, but next step is to make them more for exception than just routine logs,
as it is the routine daily log that ends up being overlooked.