Ubuntu Version:
Ubuntu Server 22.04.5 LTS (GNU/Linux 5.15.0-160-generic x86_64)
Problem Description:
Command line ‘mail’ does not work for root. I have a back up script that runs as sudo under a user we will call ‘user’ for now. I noticed after some updates a few days back it quite sending the email to report on the backup. After a little testing I found I can still send mail fine as ‘user’ but as soon as I switch to root with ‘sudo su’ it no longer works. It had worked fine up to a few days ago.
I have included the output of the mail commands here.
root@servername:/home/username# mail --debug-level=3 -s "Backup finished successfully." myemail@domain.com <<< "test mail"
mail: sendmail binary: /usr/sbin/sendmail
mail: source=system, name=root, passwd=x, uid=0, gid=0, gecos=root, dir=/root, shell=/bin/bash, mailbox=/var/mail/root, quota=0, change_uid=1
mail: source=system, name=root, passwd=x, uid=0, gid=0, gecos=root, dir=/root, shell=/bin/bash, mailbox=/var/mail/root, quota=0, change_uid=1
mail: mu_mailer_send_message(): using From: root@servername
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=root, passwd=x, uid=0, gid=0, gecos=root, dir=/root, shell=/bin/bash, mailbox=/var/mail/root, quota=0, change_uid=1
root@servername:/home/username# exit
exit
username@servername:~$ mail --debug-level=3 -s "Backup finished successfully." myemail@domain.com <<< "test mail"
mail: sendmail binary: /usr/sbin/sendmail
mail: source=system, name=username, passwd=x, uid=1000, gid=1000, gecos=username, dir=/home/username, shell=/bin/bash, mailbox=/var/mail/username, quota=0, change_uid=1
mail: source=system, name=username, passwd=x, uid=1000, gid=1000, gecos=username, dir=/home/username, shell=/bin/bash, mailbox=/var/mail/username, quota=0, change_uid=1
mail: mu_mailer_send_message(): using From: username@servername
mail: Sending headers...
mail: Sending body...
mail: /usr/sbin/sendmail exited with: 0
This has not changed but I originally set up command line email by editing the file /etc/ssmtp/ssmtp.conf.
username@servername:~$ sudo cat /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster
# 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
# Where will the mail seem to come from?
#rewriteDomain=
# The full hostname
#hostname=servername
# 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
# The user that gets all the mails (UID < 1000, usually the admin)
root=myemail@domain.com
# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also http://mail.google.com/support/bin/answer.py?answer=78799
mailhub=smtp.gmail.com:587
# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com
# The full hostname
hostname=localhost
# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes
# Username/Password
AuthUser=username@gmail.com
AuthPass=something
# Email 'From header's can override the default domain?
FromLineOverride=yes