I have configured my Debian server to use msmtp
for sending mails. Current use case are for example sending a daily report from logwatch
to my isp email.
echo "$body" | mutt -s "$topic" -- "myisp@email.com"
I have configured msmtp
by means of a global msmtprc
file located at /etc/msmtprc
. Contents shown below.
The next thing I want to configure is that my email for my root account (e.g., output from crontabs) is sent to my isp email as well.
I have googled around and found, for example on the Arch wiki, that I should just configure my aliases. Which I have done so at the bottom of the msmtp configuration file.
However, after running newaliases
, and trying to execute
echo test | mail -s "test message" root
I get the error
send-mail: /etc/aliases: line 2: invalid address 'postmaster'
Can't send mail: sendmail process failed with error code 78
I am unsure how I can fix this. The alias shown below is what was already present. I only added the gmail address.
I think I could just put a new aliases file but that might break other services that rely on this. I.e., I don't know what the proper way to fix this is.
/etc/aliases
# /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
root: christphe, christophe.detroyer@gmail.com
/etc/msmtprc
# ------------------------------------------------------------------------------
# msmtp System Wide Configuration file
# ------------------------------------------------------------------------------
# A system wide configuration is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
# ------------------------------------------------------------------------------
# Accounts
# ------------------------------------------------------------------------------
account isp
host mail.isp.net
port 587
from admin@isp.com
auth login
user admin@isp.com
password foobar
syslog LOG_MAIL
logfile /var/log/msmtp.log
# ------------------------------------------------------------------------------
# Configurations
# ------------------------------------------------------------------------------
# Construct envelope-from addresses of the form "user@oursite.example".
#auto_from on
#maildomain fermmy.server
# Use TLS.
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# Syslog logging with facility LOG_MAIL instead of the default LOG_USER.
# Must be done within "account" sub-section above
#syslog LOG_MAIL
# Set a default account
account default : isp
aliases /etc/aliases
# ------------------------------------------------------------------------------#
Best Answer
Update 2019-10-17
msmtp version 1.8.6 (released 2019-09-27) now has native support for chained/recursive alias expansion in
/etc/aliases
. See https://marlam.de/msmtp/news/msmtp-1-8-6/.Original Answer
So, I had the exact same issue when I migrated from ssmtp to msmtp. The issue is caused by the
is_address()
function in aliases.c. Basically, if the target of the alias doesn't contain'@'
, msmtp thinks it's invalid and dies. You can work around this by just appending @ to all the aliases that redirect to root.In your example, you would modify
/etc/aliases
as follows:I plan to log a bug/issue against msmtp to get this behavior changed so it just works and will update this answer then.