4

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
# ------------------------------------------------------------------------------#
1
  • msmtp only accepts aliases of the form root: christophe.detroyer@gmail.com so I should create a /etc/aliases.msmtp with just that line for the moment and change your config. Is mail a link to msmtp? Do you have postfix or sendmail installed too?
    – meuh
    Oct 24, 2016 at 16:48

3 Answers 3

7

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:

# /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

I plan to log a bug/issue against msmtp to get this behavior changed so it just works and will update this answer then.

4
  • 1
    Wouldn’t the last line need to be root: christphe@, christophe.detroyer@gmail.com?
    – Scott
    Jul 23, 2019 at 2:52
  • @Scott yes, it would. Fixed now.
    – JoeNahmias
    Jul 23, 2019 at 9:43
  • wait, why do you need two entries for the last alias?
    – Gaia
    Mar 2, 2020 at 5:42
  • 2
    @Gaia that was part of the question above. My guess is that wanted the emails to root to end up at his local mailbox on the server as well as on his isp mailbox.
    – JoeNahmias
    Mar 4, 2020 at 14:11
3

Found 2 things today on this when trying msmtp for the first time.

  1. /etc/aliases default of postmaster: root gave things heartburn. Only revealed by msmtp -v

    • solved by changing line to postmaster: root@somewhere.com
  2. put aliases /etc/aliases in /etc/msmtprc or ~/.msmtprc

0

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.

  1. Add a line like this on /etc/msmtprc:
   aliases /etc/aliases.msmtp
  1. Create the file /etc/aliases.msmtp that contains this line:
   default: christophe.detroyer@gmail.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.