We all know Gmail or Outlook and they have this great feature where you can use multiple aliasses for only one real emailaddress like username+tag@gmail.com. It is called address tagging, plus-addressing, sub-addressing or even sub-aliassing, and existed way before these services came around. This method allows you to ‘tag’ the sender of the mails and apply custom filtering. Also it allows you to see if they are sharing your emailaddress with other parties.

  1. How it works
  2. — Postfix
  3. — Validating forms
  4. Configuration (tl;dr)
  5. Related stuff

How it works

Normally you have an address like username@gmail.com. With tagging you can use addresses like username+tag@gmail.com while your normal address remains the same. For example, mails to username+ebay@gmail.com are delivered to username@gmail.com and in the inbox filters you can create a rule to move all username+ebay@gmail.com mails to another folder.

For mail services like Gmail and Outlook.com it works out of the box. When you run your own mailserver, especially Postfix, you may first need to enable this feature.

— Postfix

To enable this behaviour in Postfix you only have to set the recipient_delimiter in main.cf and reload the daemon, but there is a catch. For some reason unknown to mankind Postfix is appending the inbound ‘tag’ to the forward email address, so that becomes othername+tag@forward.tld causing problems with delivery. Postfix attempts to tell the mailserver at ‘forward.tld’ in the SMTP RCPT TO command it has mail for the ‘othername+tag’ user, which doesn’t exist since it should be only ‘othername’. You need to rewrite the delivery address using recipient_canonical_maps.

— Validating forms

Okay, so finally you set up plus tagging but then there is yet another problem: Javascript forms. You know the kind that attempts to validate the emailaddress. They quiet often refuse the + sign because it is not a so called word-character in the regular expression matching they perform. Those often only include A to Z, 0 to 9, period, underscore and hyphen. The last one, hypen, is not very common in emailaddresses so you can use the - too in your address tagging configuration.

Configuration (tl;dr)

First in /etc/postfix/main.cf add or set:

# Enable address-tagging for + and - characters
recipient_delimiter = +-

# Remove the tag from the forward address
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_maps

Now add this to /etc/postfix/recipient_canonical_maps (one line!)

/^(.+)[\+\-].+@(.*)/ ${1}@${2}

And reload postfix

sudo service postfix reload

That’s all.

Note that any alias or forward configured matching the tagged address will override this configuration.

A sidenote on testing: when sending mail to yourself, even via forwarders, Gmail will accept the mail but won’t deliver it to your inbox. That is because it is counted as a duplicate. Better test from another account.