Introduction
The Postfix software is responsible for transferring or receiving mails from other SMTP server using SMTP protocol. It uses a concept called address class to group recipients based on their mail delivery method and only accept mail from domains in the address class. There are three types of address classes:
- Canonical domains (also called local domains)
- Hosted domains (Virtual mailbox domains + Virtual alias domains)
- Relay domains
And finally there are two mandatory email addresses for every domain that you host. postmaster@domain
and abuse@domain
. These requirements are documented in RFC 521 and RFC 2142. Be sure to add aliases for them. If an email to those addresses will bounce your domain reputation will suffer.
Canonical domains
In most cases, the Postfix systems are the final destination for only a few domain names. These domain names are the host name and/or IP address of the machine that Postfix running on. These domains are called canonical domains.
Mails to canonical domains are delivered using a Unix-like mail delivery method. It only accepts mail from/to valid user accounts, or in other words, it checks the username in the /etc/passwd
file and then stores the mail in the /var/mail/username
directory.
The disadvantage of this address class is that we cannot have a Postfix server responsible for two domains and two mail directories if the recipient's email address is the same. If Postfix receives emails for recipients user1@example1.com
and user1@example2.com
, it will store both emails in the mail directory /var/mail/user1
because of Unix-like mail delivery method.
Hosted domains
Besides the canonical domains, Postfix can be configured to be the final destination for any number of additional domains. These domains are called hosted domains because they are not directly associated with the host name of the machine that Postfix running on.
We can use a text file, database or LDAP to specify the domains that Postfix is responsible for, the email address and the mail directory of the recipient on disk to store the emails.
Postfix expects this data in the form of a mapping. The mapping is a two-column table, the left column is considered the key and the right column is considered the value. Here is an example mapping that shows valid email addresses and the path to the mail directory on disk:
Virtual mailbox (key) | Virtual mailbox location on disk (value) |
---|---|
user1@example1.com | /var/vmail/example1.com/user1/Maildir |
user2@example1.com | /var/vmail/example1.com/user2/Maildir |
user1@example2.com | /var/vmail/example2.com/user1/Maildir |
Before checking if a specific email address is valid, Postfix first checks if it is responsible for the domain. This is done by the following mapping:
Virtual domain | Whatever |
---|---|
example1.com | xxxx |
example2.com | yyyy |
Note the second column which contains a random string because Postfix expects the data to be in form of mapping, but it will not use the second column data when checking for a valid domain.
These all you need to get a functional mail server. However Postfix provides another useful feature called aliases. An alias is a redirection (or forwarding) of one email address to one or more other addresses.
Virtual email address | Redirect to |
postmaster@example.org | user1@example1.com |
jack@example.com | user1@example1.com,user1y@example2.com |
- Redirect emails for postmaster@example.org to
user1@example.org
. - Keep a copy of an incoming email for
user1@example.com
in his mailbox and send another copy touser@example2.com
. You can use multiple email addresses seperated by commas.
Relay domains
Relay domains are domains for which the Postfix does not handle delivery but forwards it to another specified SMTP server.