Postfix, canonical_classes, and cron mail

postfix

I've come across a situation in Postfix where it seems that my configuration is being ignored. I have a home network where the machines are named hostname.fakedomain, and a colo mail host with a real domain example.com. On my home machine, Postfix is configured to rewrite envelope addresses to use the real domain example.com, but to preserve the headers as-is. I keep this setup because I want mail to be delivered to my colo mail server, but I like preserving the headers so that I can see at a glance which machine on my home network sent which mail.

Relevant details:

  • Arch Linux
  • Postfix 2.7.2
  • /etc/postfix/canonical:

    @hostname.fakedomain postmaster@example.com

  • "postconf -n" (partial output):

    alias_database = $alias_maps
    alias_maps = hash:/etc/postfix/aliases
    canonical_classes = envelope_sender, envelope_recipient
    canonical_maps = hash:/etc/postfix/canonical
    mydestination = 
    myhostname = hostname.fakedomain
    relay_domains = 
    relayhost = example.com

Normally, this works just fine: local mail on my desktop is delivered to the postmaster account on my mail server, but the headers are not rewritten. However, if the mail as provided to the sendmail binary is missing the From: header, then the header is rewritten to From: root <postmaster@example.com>. Since canonical_classes doesn't include "header_sender", this doesn't seem like it should happen. What I thought would happen is that Postfix would add From: root@hostname.fakedomain. Also, I know that this is due to the canonical map, because if I change the address there to "otheraddress@example.com", the headers change as well.

One possible workaround would be to pipe each cron entry's output through /bin/mail, but I would prefer a Postfix configuration fix, so that this works for any mail that is missing a From: header, rather than just cron mail.

Is this actually a bug in Postfix, or am I misunderstanding how canonical_classes should work in this situation?

Best Answer

Might check these two: remote_header_rewrite_domain and local_header_rewrite_clients

The latter defaults to "permit_inet_interfaces" which, in the description of this other parameter, might give you the answer?

always_add_missing_headers (default: no):
   Always add (Resent-) From:, To:, Date: or Message-ID: headers when not
   present.  Postfix 2.6 and later add these headers only when clients
   match the local_header_rewrite_clients parameter setting.  Earlier
   Postfix versions always add these headers; this may break DKIM
   signatures that cover non-existent headers.**

Even though the default is no, perhaps the local_header_rewrite_clients parameter not being empty is causing this.

However, I might also add the following (from the man page):

The canonical(5) mapping is not to be confused with virtual alias
support or with local aliasing. To change the destination but not the
headers, use the virtual(5) or aliases(5) map instead.**

While what you're doing should work, perhaps using virtual/aliases would work better?

Oh, also just found that there are sender_canonical_classes and recipient_canonical_classes parameters as well. May want to check on those.