2

What I am trying to achieve is that any email coming to joe@example.com gets rewritten to bob@example.com and delivered to bob@example.com.

Both canonical_maps and virtual_alias_maps work for delivering to the alternate recipient. When I read the doc it tells me that with the canonical_maps, cleanup does a full rewrite.

However, in practice the email still has the to of the original recipient. So when looking at the email in bob's mailbox, it shows an email to joe.

Somehow I feel I am missing something here.

Configuration:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
bounce_queue_lifetime = 2d
canonical_maps = hash:/etc/postfix/canonical
config_directory = /etc/postfix
header_checks = pcre:/etc/postfix/header_checks
home_mailbox = Maildir/
html_directory = /usr/share/doc/postfix/html
inet_interfaces = all
mailbox_size_limit = 0
maximal_queue_lifetime = 4d
milter_default_action = accept
milter_protocol = 2
mydestination = ...
myhostname = ...
mynetworks = ...
myorigin = /etc/mailname
non_smtpd_milters = inet:localhost:8891
readme_directory = /usr/share/doc/postfix
recipient_delimiter = +
relayhost =
smtp_fallback_relay = ...
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_milters = inet:localhost:8891
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient_access        permit_mynetworks       reject_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
transport_maps = hash:/etc/postfix/transport
virtual_alias_maps = hash:/etc/postfix/virtual

Logs:

Sep 25 09:40:30 server1 postfix/smtpd[28285]: connect from mail-la0-f66.google.com[209.85.215.66]
Sep 25 09:40:31 server1 postfix/smtpd[28285]: 7CA784EDB6: client=mail-la0-f66.google.com[209.85.215.66]
Sep 25 09:40:31 server1 postfix/cleanup[28339]: 7CA784EDB6: message-id=<CAJjncucnGM532xhcn37VAwmwQoYEwOUfE_A33-oyJJH5PqPUcA@mail.gmail.com>
Sep 25 09:40:31 server1 postfix/qmgr[7593]: 7CA784EDB6: from=<sender@email.com>, size=1813, nrcpt=1 (queue active)
Sep 25 09:40:32 server1 postfix/smtpd[28285]: disconnect from mail-la0-f66.google.com[209.85.215.66]
Sep 25 09:40:32 server1 postfix/smtp[28593]: 7CA784EDB6: enabling PIX workarounds: disable_esmtp delay_dotcrlf for ...[...]]:25
Sep 25 09:40:33 server1 postfix/smtp[28593]: 7CA784EDB6: to=<bob@example.com>, orig_to=<joe@example.org>, relay=...[...]:25, delay=1.6, delays=0.45/0/0.42/0.73, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 98F729600E)
Sep 25 09:40:33 server1 postfix/qmgr[7593]: 7CA784EDB6: removed
ETL
  • 6,513
  • 1
  • 28
  • 48

1 Answers1

2

From the mail.log, looks like you want to rewrite the email from the remote client. The default setting of postfix rewrite prevent this happened.

Excerpt from Postfix Rewriting README

Postfix versions 2.2 give you the option to either not rewrite message headers from remote SMTP clients at all, or to label incomplete addresses in such message headers as invalid. Here is how it works:

  • Postfix always rewrites message headers from local SMTP clients and from the Postfix sendmail command, and appends its own domain to incomplete addresses. The local_header_rewrite_clients parameter controls what SMTP clients Postfix considers local (by default, only local network interface addresses).

  • Postfix never rewrites message header addresses from remote SMTP clients when the remote_header_rewrite_domain parameter value is empty (the default setting).

  • Otherwise, Postfix rewrites message headers from remote SMTP clients, and appends the remote_header_rewrite_domain value to incomplete addresses. This feature can be used to append a reserved domain such as "domain.invalid", so that incomplete addresses cannot be mistaken for local addresses.

So, the simplest solution is don't leave parameter remote_header_rewrite_domain with empty value. You need to provide value to this parameter with value such as

remote_header_rewrite_domain = domain.invalid

Or you can use static:all on parameter local_header_rewrite_clients so postfix will consider all remote client as local.

local_header_rewrite_clients = static:all

Source: Official docs of Postfix Address Rewriting

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • Thanks mate! I knew I was missing something - it was right there in the text I was reading, somehow just kept missing that NOTE paragraph! – ETL Sep 25 '15 at 19:09
  • One thing I just noticed however, the X-Original-To does not get rewritten. I'll check around but if you know the answer to that one, let me know! – ETL Sep 25 '15 at 19:15
  • Hmmm weird. From your logs above, you relay email to another server via *smtp*. But from this page http://postfix.1071664.n5.nabble.com/virtual-alias-maps-and-X-Original-To-tp9124p9125.html smtp service shouldn't prepend X-Original-To header – masegaloeh Sep 26 '15 at 03:39
  • Sorry, in this case I was testing with, there is a virtual entry for the rewritten address, hence the X-Original-To, I figured out a solution for what I needed so we're good. Thanks for help. – ETL Sep 26 '15 at 03:42
  • Feel free to edit my answer to put your solution... :) – masegaloeh Sep 26 '15 at 03:45