Forward a forwarded mail with postfix, based on rules

forwardingpostfix

How can I get postfix to forward an incoming email to one or more different local alias(es), if the address I want the rule to be based on, is not the recipient? The address I want to act on is from a forwarded mail.

It goes like this:
On external account:

  • voicemail addressed to 123+voicemail@externaldomain gets delivered to the main
    myname@externaldomain account. (this combines normal text mail and mail with voice attachments)
  • All mail is forwared to my server using tonline@mydomain

On local postfix server:

  • Now I want to forward only voice mail originally addressed to 123+voicemail@externaldomain to my aliases for voice@mydomain and voice@myotherdomain
    That's why I can't simply use bcc_maps

  • In virtual_alias_maps I tried:

    • Using virtual_alias_maps I'm able to redirect
      voice@mydomain to myvoice@mydomain, myvoice@myotherdomain
      but this includes regular mail, too.

    • So I tried a rule like
      123+voice@externaldomain voice@mydomain, voice@myotherdomain
      but this doesn't trigger.

example mail when finally received by me using the rule from my first attempt:

Return-Path: <123@externaldomain>
X-Original-To: voice@mydomain
Delivered-To: myvoice@mydomain    
From: 456 <456@externaldomain>
To: 123+voice@externaldomain
Subject: Call from 456

Best Answer

Since your decision is totally dependant on To header, you can add header_checks

#/etc/postfix/main.cf
# ...
# ...
header_checks = regexp:/etc/postfix/header.re
# ...

#/etc/postfix/header.re
/^To:(.*)123+voice@externaldomain/        REDIRECT  whoever@whateverdomain.tld
Related Topic