SMTP Server Mail Alerts using TLS and authentication issue - email

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

Related

sendemail unable to connect to stunnel on IP 127.0.0.1 (Port 259)

I recently setup a new Windows 10 computer. On it I transfered scripts I am using elseware. The script involves sendemail.exe sending out an email using stunnel to gmail.
The script is as follows:
c:\Program Files (x86)\sendEmail>sendEmail.exe -l c:\temp\sendemail.log -t email#gmail.com -u "Email Subject" -m "Email Message" -s 127.0.0.1:6259 -f senderemail#gmail.com -xu senderemail -xp 123456789012345 -o tls=auto
The above commands fails with the following error: '''Aug 07 15:45:15 dell-pms sendEmail.exe[5196]: ERROR => Connection attempt to 127.0.0.1:6259 failed: IO::Socket::INET: connect: Unknown error'''
Replacing 127.0.0.1 with localhost fails.
Repeating the command but replacing the IP address (127.0.0.1) with the computer's IP address 192.168.16.76 works.
The hosts file is the default (everything remarked).
Any suggestion how to diagnose.

SSMTP fails after migrating to Buster

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.

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.