SSMTP fails after migrating to Buster - email

SSMTP was working for years now on my RPi - latest on stretch.
Now I migrated to buster - and after this step it now fails.
$ cat /etc/ssmtp/ssmtp.conf
root=user#mydomain.com
mailhub=smtp.gmail.com:587
hostname=localhost
UseSTARTTLS=YES
AuthUser=user#gmail.com
AuthPass=very_secret
FromLineOverride=YES
$ echo "MailBody"|mail --debug-level=3 -s "My Subject" mailaddress#domain.com
mail: sendmail binary: /usr/sbin/sendmail
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
mail: mu_mailer_send_message(): using From: user#localhost
mail: Sending headers...
mail: Sending body...
mail: /usr/sbin/sendmail exited with: 1
mail: progmailer error: Process exited with a non-zero status
mail: cannot send message: Process exited with a non-zero status
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
$ echo $?
36
I have a lot of shell-scripts sending mails with commands like:
echo "MailBody"|mail -s "My Subject" emailaddress#domain.com
=> so if SSMTP is no longer supported, I would neeed a solution following that syntax ...
thanks for any help!

I fixed this by switching away from ssmtp (which some sources say being unmaintained) to msmtp (https://wiki.debian.org/msmtp).
This could or could not apply to you, try to check the error code by sending an email directly via /usr/sbin/ssmtp -v ...., I had exit 36 (echo $? to get the code).
If you are in a similar situation and want to give msmtp a try, these the steps I followed:
Install:
$ sudo apt remove ssmtp
$ sudo apt install msmtp msmtp-mta
Configure (I'm not configuring GMail, I use Dreamhost email service, so your details might be different):
$ cat /etc/msmtprc
# Set default values for all following accounts.
defaults
auth on
tls on
tls_starttls off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /tmp/msmtp.log
# Raspberry Pi
account rasp
host smtp.dreamhost.com
port 465
from raspberry#<REDACTED>
user raspberry#<REDACTED>
password <PLAINTEXTPASSWORD>
# default account
account default : rasp
For comparison, this was my /etc/ssmtp.conf file:
root=postmaster
mailhub=smtp.dreamhost.com:465
AuthUser=raspberry#<REDACTED>
AuthPass=<REDACTED>
UseTLS=YES
UseSTARTTLS=YES
TLS_CA-File=/etc/ssl/certs/ca-certificates.crt
hostname=<REDACTED>.org
FromLineOverride=NO
Set msmtp as default MTA. I've added the last line to my mail.rc file:
$ cat /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
set mta=/usr/bin/msmtp
[NOTE]: There is also an issue with msmtp in that it's not populating automatically the "From:" header in the message so emails get rejected, to fix it, when calling mail make sure to do it manually:
echo TEST | mail -a "From: raspberry#<REDACTED>" --debug-level 10 -s '[rasp] server' <REDACTED>#gmail.com
This makes email sending work again from my Raspberry Pi on Debian buster/sid.

Related

SMTP Server Mail Alerts using TLS and authentication issue

I am a bit new in using SMTP server Alert configurations on AIX 7.1 OS . I am currently using below syntax which is running fine :
mail -s "Subject" "abc#test.com" < /path/to/my/input.txt
but we are now migrating our SMTP server with authentication and TLS enable but I am unable to do so. please guide me what am I doing wrong:
echo "This is the message body and contains the message" | mailx -v -s "This is the subject" -S smtp=smtp://newsmptp.test.com:25 -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="temp" -S smtp-auth-password="Abc#123" -S ssl-verify=ignore "abc#test.com
The error I get is:
mailx: Not a recognized flag: S

Raspberry PI - Send mail from command line using GMAIL smtp server

How can I send email from Raspberry Pi using my gmail account?
I would like to send mail from command line and use this method in my scripts.
Envirenment:
Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
I use this method on my Raspberry Pi 3 devices:
Google account setting
Login to your gmail account
Go to: Settings -> Accounts and Import -> Other Google Account settings
Go to: Personal info & privacy -> Account overview
Go to: Sign-in & security -> Connect apps & sites
Set option Allow less secure apps to ON
Install SSMTP
sudo apt-get install ssmtp
Save original conf file
sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
Create new conf file (with vi, or some other text editor)
sudo vi /etc/ssmtp/ssmtp.conf
file content
root=your_account#gmail.com
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=your_account#gmail.com
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES
# Debug=Yes
Secure conf file
sudo groupadd ssmtp
sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
If you have error on this step like ''cannot access'' ... you must find ssmtp file and use that path: sudo find / -name "ssmtp"
sudo chown :ssmtp /usr/sbin/ssmtp
sudo chmod 640 /etc/ssmtp/ssmtp.conf
sudo chmod g+s /usr/sbin/ssmtp
Sending mail from (only one) command line
echo "This is a test" | ssmtp recipient.address#some_domain.com
or
printf "To: recipient.address#some_domain.com\nFrom: RaspberryPi3\nSubject: Testing send mail from Raspberry\n\nThis is test. Best Regards!\n" | ssmtp -t
Sending mail from file test.txt
Make file with similar content:
To: recipient.address#some_domain.com
From: your_account#gmail.com
Subject: Testing send mail from Raspberry
This is test mail (body)
Best Regards!
Now you can send mail from file
ssmtp recipient.address#some_domain.com < test.txt
That's all :)

postfix/sendmail[4825]: fatal: usage: sendmail [options]

I am new in shell script,I have try to send mail using shell script as below code
from="test#mail.com"
to="recive#mail.com"
subject="Title here"
body="This is the body of our email"
declare -a attachments
attachments=( 'test.doc')
declare -a attargs
for att in "${attachments[#]}"; do
attargs+=( "-a" "$att" )
done
/usr/sbin/sendmail -s "$subject" -r "$from" "${attargs[#]}" "$to" <<< "$body"
Try to run in console show this type of error
sendmail: invalid option -- 's'
sendmail: invalid option -- 's'
sendmail: fatal: usage: sendmail [options]
And mail log show this type error
postfix/sendmail[4825]: fatal: usage: sendmail [options]
sendmail is giving you the answer in the error message: invalid option -- 's', which is in fact the case. There is no -s option to sendmail as sendmail is generally not considered a command-line mail program.
You will serve yourself much better using mailx or heirloom-mailx or the like. (it is the same program, it has just shuffled names over the past several years). It may already be installed on your system. Check with type mailx
For use/options see: mailx(1) - Linux man page

CFG Error email receiving every 5 minutes from Zabbix on Unix server

I have configured sSMTP on myzabbixserver Unix system which successfully delivers Zabbix alerts via Gmail. Strangely I am receiving an email in my Gmail inbox (which I am using as From address for sSMTP config) EVERY 5 minutes with following details:
from: root <my.zabbix#gmail.com>
to: root
bcc: my.zabbix#gmail.com
subject: Cron <root#myzabbixserver> if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
body: ERROR: CFG Error in "workdir", line 8: Working directory /var/www/mrtg does not exist
sSTMP.conf
root=my.zabbix#gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
AuthUser=my.zabbix#gmail.com
AuthPass=my.password
hostname=myzabbixserver
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthMethod=LOGIN
gmail.sh script which Zabbix uses to send email alerts:
#!/bin/bash
to=$1
subject=$2
body=$3
echo $body | /usr/bin/mailx $to -s "$subject"
What does that email mean and how can I stop it ?
This is not a Zabbix problem, but mrtg problem. Your mrtg cron job /etc/cron.d/mrtg is failing and you are receiving this cron error output.
Solutions:
configure mrtg correctly (http://www.debianhelp.co.uk/mrtg.htm)
uninstall mrtg/disable mrtg cron job
...

How to stop cron daemon from warning about empty emails

I am running a cron job which delivers a mail with a custom subject. The crontab entry is similar to :
python script.py 2>&1 | mail -s "Custom Subject" user#gmail.com
The mail from the mail -s is delivered to the user#gmail.com inbox just fine. But user#gmail.com receives an extra mail from the cron-daemon with the subject as python script.py 2>&1 | mail -s "Custom Subject" user#gmail.com and the email body being a warning about an empty mail being delivered. I am not sure where this extra email is originating from and would really like to know how to stop it.
Maybe related to: Extra email from Cron Daemon when running an email list script
Maybe you are probably getting the (empty) output of the mail command.
Try
python script.py 2>&1 | mail -s "Custom Subject" user#gmail.com >/dev/null 2>&1
Alternatively, set
MAILTO=""
at the beginning of your crontab.