juanluisbaptiste/docker-postfix

Overwrite Sender Header

TreasureMaster opened this issue · 3 comments

Hello!
I ran into the problem of sending mail via smtp.yandex.ru. This service requires the From and Sender headers to match. For example i get: "Sender: root@e379890e3f75" and "550 5.7.0 Sender or From header address rejected: not owned by authorized user". Now I am creating my dockerfile based on your image. I add this line run.sh:
echo -e "/^Sender:.*$/ REPLACE Sender: $OVERWRITE_FROM" >> /etc/postfix/smtp_header_checks
Can you add a variable to duplicate the From and Sender headers?

PR welcome.

Have you tried using ENV:ALWAYS_ADD_MISSING_HEADERS=yes and ENV:OVERWRITE_FROM="My Name" <my.mail@yandex.ru> ?

This was introduced on 11 Oct 2021 maybe you haven't already the newest release? 99a2397

For me this is working.

best regards
realizelol

Since this issue is still marked 'open', I felt okay with adding my 2 cents.

I am relaying email from a Linux box (Debian 11, Postfix as smarthost relay) to docker-postfix. With my previous email provider, that worked like a charm. All the email sent from the Linux box was delivered. However, the new email provider I am using does not accept the emails docker-postfix relays to it.

The log show the famous "Sender address rejected: not owned by user". Apparently the From line isn't rewritten, although I have the OVERRIDE_FROM environment variable set to a valid email address. However, sending a mail from the docker-postfix container itself does override the From line. The log shows:

smtprelay | Sep 19 20:03:24 smtprelay postfix/smtp[217]: DAA6D4AF: replace: header From

That log line does not show up when I send an email from the Linux box. I did some digging around and I found that Postfix does not use the smtp_header_checks when email is relayed with SMTP from another box. A working work-around is using the following Postfix configuration:

sender_canonical_maps = static:sender@example.com
local_header_rewrite_clients = permit_inet_interfaces permit_mynetworks

If using that configuration, the smtp_header_checks can be omitted. Note that permitted_mynetworks is mandatory, otherwise Postfix will not apply the canonical map.

I also noticed that the header provided in SMTP_HEADER_TAG is applied twice in the email. I need to look into that a bit further.

Any comments?