5

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" -- "[email protected]"

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, [email protected]

/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 [email protected]
auth login
user [email protected]
password foobar
syslog LOG_MAIL

logfile /var/log/msmtp.log

# ------------------------------------------------------------------------------
# Configurations
# ------------------------------------------------------------------------------

# Construct envelope-from addresses of the form "[email protected]".
#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
# ------------------------------------------------------------------------------#
  • msmtp only accepts aliases of the form `root: [email protected]` 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 '16 at 16:48

4 Answers4

8

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@, [email protected]

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

JoeNahmias
  • 318
  • 3
  • 6
6

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

  2. put aliases /etc/aliases in /etc/msmtprc or ~/.msmtprc

user1810087
  • 103
  • 4
Bill
  • 61
  • 1
  • 2
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: [email protected]
dashohoxha
  • 236
  • 2
  • 6
0

msmtp and AppArmor don't play well together.  AppArmor was okay with msmtpd reading /etc/aliases but balked at reading /etc/aliases.msmtp.

I found the problem by using the -v option of msmtp and sending a test mail.

I recommend sticking to /etc/aliases.

Rick
  • 1