Software your mail server will use
The configuration described here uses these software components (the versions are Debian Wheezy’s default versions):
- Debian (Release 7.0 – Code name “wheezy”)
- Postfix (2.9.6) for receiving incoming emails from the internet and for forwarding your users’ sent emails
- Dovecot (2.0) to store emails on your hard disk and allow users to access their emails using POP3 and IMAP
- Roundcube (0.7.2) as a beautiful webmail interface so users can read their emails using a web browser and manage their email rules
- MySQL (5.5.31) as the database backend storing information about domains, user accounts and email forwardings
The wonderous ways of an email
Let us start with an overview of how receiving and sending email works.
The green circles show what will happen when you receive an email.
- A remote mail server requests a TCP connection on port 25 to your mail server. Your firewall lets that connection through and the Postfix “smtpd” process will accept it.
- Postfix starts speaking SMTP (the “simple mail transfer protocol”) and gathers information who the alleged sender and the intended recipient addresses are. While the connection is still active Postfix does a couple of checks and may decide to reject the email.
- Postfix will also check real-time black lists (RBLs) via DNS to see if the sending IP address should be distrusted. For example it will reject senders running on a dynamic IP address because that almost always means the email is coming from yet another infected Windows workstation or hacked server and is likely spam.
- Postfix asks Dovecot whether the recipient email address belongs to an actually known user.
- Dovecot checks the MySQL database and looks for an entry for the email address in question.
- If the user exists then Postfix will accept the email and forward it to Dovecot.
- Dovecot stores the received email in a file in the /var/vmail directory.
- The user fetches new email using the POP3 or IMAP protocols from Dovecot.
Now let’s assume the user replies to the email and wants to send the reply. This is depicted by the blue circles.
- (A) The user’s mail client establishes an SMTP connection to Postfix. It sends a username and password to authenticate.
- (B) Postfix asks Dovecot whether the username and password are correct. This prevents accepting unauthorized email from untrusted parties.
- (C) Dovecot searches for the account information of the sending user in the MySQL database. It tells Postfix whether the authentication was successful.
- (D) Postfix needs to find out which server on the internet the email needs to be sent to. It asks a DNS (domain name service) server for an MX (mail exchanger) record of the receiving domain. If successful it will get the name of the server back and will know where to send the email.
- (E) Postfix connects to the responsible server of the receiving user, establishes an SMTP connection and sends the email.
That much for a general overview.