msmtp icon indicating copy to clipboard operation
msmtp copied to clipboard

Recipient not rewritten for mail to a local user when address contains the local hostname/mailname

Open LaXiS96 opened this issue 10 months ago • 1 comments

Hello, I am running v1.8.23 on Debian 11 (built from Debian 12 sources, since Debian 11 only has v1.8.11 and that doesn't support allow_from_override).

I have noticed that running a simple test command like echo test | mail root would not work on Debian 11, while it would on Debian 12. The difference is that on 11, the mail command sets the To: header to the full address including the hostname/mailname, while on 12 it does not.

When the recipient is specified as a full address containing the hostname/mailname, msmtp will forward mail without rewriting the recipient to the one specified by the aliases. This can result in undelivered mail (depending on the recipient the caller sets), since the local host clearly cannot receive mail.

Here is the behavior on Debian 11 (icecream.example.org is the local FQDN and also /etc/mailname):

laxis@icecream:~$ echo test | mail --debug-level=mailer root
mail: sendmail binary: /usr/sbin/sendmail
mail: mu_mailer_send_message(): using From: laxis
mail: exec /usr/sbin/sendmail argv: /usr/sbin/sendmail -oi -f [email protected] -t
mail: Sending headers...
mail: Header: To: <[email protected]>
mail: Header: X-Mailer: mail (GNU Mailutils 3.10)
mail: Header:
mail: Sending body...
mail: /usr/sbin/sendmail exited with: 0

While on Debian 12:

laxis@icecream:~$ echo test | mail --debug-level=mailer root
mail: sendmail binary: /usr/sbin/sendmail
mail: mu_mailer_send_message(): using From: [email protected]
mail: exec /usr/sbin/sendmail argv: /usr/sbin/sendmail -oi -f [email protected] -t
mail: Sending headers...
mail: Header: To: root
mail: Header: User-Agent: mail (GNU Mailutils 3.15)
mail: Header: Date: Fri, 29 Mar 2024 20:21:49 +0100
mail: Header:
mail: Sending body...
mail: /usr/sbin/sendmail exited with: 0

/etc/msmtprc:

account default
host smtp.zoho.eu
port 465
tls on
tls_starttls off
auth on
user [email protected]
password redacted
from [email protected]
syslog LOG_MAIL
aliases /etc/aliases
set_from_header on
allow_from_override off

/etc/aliases:

default: [email protected]

Is there already some configuration option to correctly treat addresses with the domain part matching the local hostname (FQDN or not) or mailname? If the answer is no, would it be a good idea to add it? Thank you

LaXiS96 avatar Mar 29 '24 19:03 LaXiS96

The -t option tells msmtp to read recipients from the mail, so it in this example it uses whatever is in the To header.

You could use aliases /etc/aliases in your configuration file with the following contents in /etc/aliases:

root: [email protected]

marlam avatar Apr 03 '24 15:04 marlam