marlam / msmtp

SMTP client with sendmail compatible interface
https://marlam.de/msmtp
GNU General Public License v3.0
176 stars 36 forks source link

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

Closed LaXiS96 closed 7 months ago

LaXiS96 commented 8 months ago

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 laxis@icecream.example.org -t
mail: Sending headers...
mail: Header: To: <root@icecream.example.org>
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: laxis@icecream.example.org
mail: exec /usr/sbin/sendmail argv: /usr/sbin/sendmail -oi -f laxis@icecream.example.org -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 icecream@example.org
password redacted
from icecream@example.org
syslog LOG_MAIL
aliases /etc/aliases
set_from_header on
allow_from_override off

/etc/aliases:

default: redacted@outlook.com

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

marlam commented 7 months ago

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: root@icecream.example.org