One of the advantages of running your own mail server is the ability to enable address forwarding for email addresses handed out to third parties. Particularly, in these times where customer hungry corporations are always looking to harvest email addresses, I make it a point to have a different account to give out so that my personal email account remains sane. But, I wanted to go one step further. Instead of handing out to the same account to all of them, I really wanted to have the ability to hand out a different one to each, that would just forward to a catch-all account. The reason this is beneficial is that allows me to easily block senders that have gone rogue, and also easily tell which ones actually sold my account to others.
Postfix allows for this capability using specified delimiters in the email address. For example, if I had an account my@domain.com
that I wanted to assign as the catchall, I could just hand out addresses like my+wholefoods@domain.com
or my+target@domain.com
and these would automatically get forwarded to the catchall account. To configure this in Postfix, open the file /etc/postfix/main.cf
or /usr/local/etc/postfix/main.cf
depending on where you installed Postfix, and add the following line:
recipient_delimiter = +-
This adds 2 delimiters, both +
and -
that can be used as valid separators that Postfix will use to parse incoming emails. Additionally, we also need another similar directive for outgoing email:
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_maps
Then, open the /etc/postfix/recipient_canonical_maps
file and add this regex:
/^(.+)[\+-].+@(.*)/ ${1}@${2}
And thats it! Every incoming email thats handled by postfix will automatically be redirected based on the prefix before the delimiters.