What process does email delivery go through?

Delivered email goes through a number of steps. You can use the various transformations along these steps to help filter or understand how mail delivery occurs.

The steps are described here:

  1. Email arrives via SMTP. The SMTP protocol requires two parameters during the transaction, a "MAIL FROM" value and a "RCPT TO" value.

    The "MAIL FROM" parameter is supposed to contain the email address of the sending party. If the email is from the "postmaster" address at the remote site, an empty value of <> is used. The value used here is completely independent of what is shown in the actual email header From line.

    The "RCPT TO" parameter specifies the recipients of the message. The value used here is completely independent of what is shown in the actual email header To/Cc lines. This is how emails that are BCC'ed to you, or have forged headers, can arrive at your account even though your address is not in the header.

  2. Any aliases, domains and subdomains are matched and translated to the "Target" values. This is done repeatedly until no more translations occur. The order is as follows:

    1. Any address of the form user@subdomain.srcdomain.com is translated to subdomain+user@srcdomain.com. A more detailed explanation of this can be found in our documentation of subdomain addressing.

    2. For an address of the form name+plus@srcdomain.com, if an alias name@srcdomain.com exists, then the address is replaced with the "Target" of the alias.

    3. If address contains a "+" part (e.g. name+srcplus@srcdomain.com) and the "Target" also contains a "+"" part (e.g. target+trgplus@targetdomain.com) then the two are combined into target+trgplus.srcplus@targetdomain.com.

    4. If no specific name@srcdomain.com alias exists, but a 'catch all' alias exists (e.g. *@srcdomain.com), then the target of that is used. If the "Target" contains an asterix (*) in it, between the "+" part and the "@" part, then it is replaced with the original name part of the address. For example, suppose:

      • The alias *@srcdomain.com exists with a "Target" of yourname+*@targetdomain.com.
      • An email sent to john@srcdomain.com will be rewritten to yourname+john@targetdomain.com.
      • If you have a folder in your account called "John", then this email will automatically be filed straight into that folder. You can also deliver straight to a subfolder by using a "Target" of yourname+parentfolder.*@targetdomain.com.
    5. If the "Target" contains commas, then it is separated on the commas into multiple target values. Each of the actions described above occurs on each of the target addresses.

  3. If the resultant target (or targets) is an external address, the email is then queued for sending to the external address.

  4. If the address is local, it is delivered to the appropriate local mailbox. During delivery, the following also occurs:

    • The original SMTP "MAIL FROM" parameter is added to the email as an X-Mail-from header.
    • The original SMTP "RCPT TO" parameter is added to the email as an X-Delivered-to header.
    • The result delivery address based on the alias and subdomain translations above is added to the email as an X-Resolved-to header.
    • If the email has any attachments, the names of the attachments are added as X-Attached headers.
    • The email is scanned by our content filter.
    • If the user has spam checking enabled, the email is spam checked.

      • Any SpamAssassin "hits" are put in the X-Spam-hits header. See SpamAsassin's documentation for a list of the main tests performed and their scores.
      • A "spam score" is put in the X-Spam-score header. It's clamped to be always >= 0, even if the actual score was negative.
  5. After that, the users "Sieve script" is run on the email. This is a script generated from the Settings → Rules screen which controls the discard/forwarding/file-into-folder actions for the email.

  6. If the final delivery address has a "+" in it, and no particular Sieve rule catches the email to file it into a specific folder, then the email is delivered to the folder name after the '+' part. Folder names are matched case-insensitively, and with the characters '_', '-', and the space character all being regarded as the same. E.g. email to username+sent_items@domain.com will be placed into the "Sent Items" folder. If no such folder exists, then the email will deliver to the standard Inbox. You can deliver to subfolders by using '.' to separate folder names.

  7. The 'envelope' value seen by the Sieve script is the resultant target value, not the original 'MAIL FROM' or 'RCPT TO' parts.

What headers are added by Fastmail?

While your email is being processed, a number of headers are added:


The X-Spam-known-sender header tells whether an email should be considered as a known sender/whitelisted. Currently we check the users contacts against the MAIL FROM address and From header address as well both addresses with the localpart replaced by * (e.g. foo@bar.com -> *@bar.com). The checks done may be expanded in the future.

Currently the following values are possible, though these may change in the future. In general you should only rely on the field starting with "yes", containing "in-addressbook" or containing one of the contact group uuid's.


In addition, on the end of that list (comma separated), we include any contact groups the address was in as:

Example headers

An example set of the above headers as they might appear on a message (although it's unlikely these would all appear on all messages):

X-Attached: ExampleHousePlans.ppt
X-Spam-known-sender: yes ("Address *@pause.perl.org in SMTP MAIL FROM is in addressbook"),
  in-addressbook, 823ac70d-9af4-4ca1-8a76-996357874b02 ("Perl")
X-Spam: spam
X-Spam-score: 4.8
X-Spam-hits: BAYES_99 3.5, HTML_MESSAGE 0.001, RCVD_IN_DNSWL_NONE -0.0001,
X-Spam-source: IP='', Host='pause.fiz-chemie.de', Country='DE',
FromHeader='org', MailFrom='org'
X-Spam-charsets: plain='utf-8', html='ISO-8859-1'
X-Resolved-to: robm+cpan@fastmail.com
X-Delivered-to: cpan@robm.fastmail.com
X-Mail-from: root@pause.perl.org
X-Spam-orig-subject: BTD
Subject: {SPAM 04.8} BTD