Customize and filter your email address for different websites with extensions and Sieve


What are extensions and Sieve?

Let's say you have an email account "tim@example.org". With extensions enabled you can register on "twitter.com" with the email "tim+twitter@example.org" and it will be delivered to you standard inbox tim@example.org!

Extensions are a feature a lot of mail servers support right from the start. Postfix for example often uses the '+' sign for this feature (the docs say "default: empty" but that depends on your distribution).

With Sieve you can set up server side filtering with scripts written in the Sieve language. There's some examples in the Dovecot wiki that might be the best explanation how it looks like.

Note that Sieve is an addon that in many cases needs to be installed and enabled maually. If you are a user of some free hoster you might not be able to benefit from Sieve. If you are a Thunderbird user you might be able to discover your hoster's abilities with the Mozdev Sieve addon.

Combining both

Now that we have multiple unique addresses that don't need any setup and we have Sieve ready to use on our mail server - let's extend Sieve's scripting to automatically match extensions and put them in their own folders.

The following example is an extract from a Sieve script and can also be found in the Pigeonhole examples.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
require ["variables", "envelope", "fileinto", "subaddress"];

# Match tim+ mails
if envelope :is :user "to" "tim" {
  if envelope :matches :detail "to" "*" {
    set :lower "site" "${1}";
  }

  if string :is "${site}" "" {
    /* Default case if no detail is specified */
    fileinto "INBOX/web/accounts";
  } else {
    fileinto "INBOX/web/accounts/${site}";
  }
  stop;
}

Put this in the running Sieve script for your tim@example.org account.

Then create subfolders in inbox/web/accounts/<site>, for example inbox/web/accounts/twitter and all emails to "tim+twitter@example.org" will be put into this folder automatically. If the folder does not exist yet, Sieve finds the error and leaves the received email in your inbox folder.

Grats, you are now able to use unique email addresses when signing up on a website - without creating any aliases or new accounts on some shady temporary-email-websites - and get them automatically categorized for you!