Every mail server that lets you send and receive email with a local mail client has three separate software components:
MTA: The Mail Transfer Agent relays mail between your server and the Internet, whether it is delivering an outside email to you, or sending an email from you. Accepted incoming mail gets added to the MTA’s queue on the server.
MDA: The Mail Delivery Agent takes mail from the MTA’s queue and saves it to individual mailboxes.
IMAP/POP3 Server: It manages users and their mailboxes as they check their email over IMAP/POP3 connections.
An incoming message is directed to your mail server via DNS.
Once it passes through the MTA and MDA, it is stored in the mailbox on the server.
When the message is requested, the IMAP/POP3 server mediates the connection between the server and the user’s local mail client.
Outgoing mail is sent from the user’s local mail client, processed by MTA, and is then sent to its destination on the Internet.
MTAs are responsible for handling SMTP connections to your server from both outside senders and your users. The most popular MTA services are:
1. Exim is modern and oriented towards flexibility. It’s secure, but not quite as security-oriented as Postfix. It is very customizable, but is one of the most complex MTAs to configure.
2. Postfix is modern, security-oriented, and very flexible. It is slightly simpler to set up than Exim.
MDAs move email from the MTA’s queue to individual mailbox directories. For example, your mailbox could be located at /var/mail/example.com/user/. MDAs are also known as Local Delivery Agents (LDAs). Different MTAs support different types of mailboxes. MDAs are often bundled with other mail-related applications.
Some of the most popular MDAs are:
1. Cyrus’s MDA is part of the Cyrus IMAP/POP3 server. Cyrus is a modern, security-oriented IMAP/POP3 server designed to run on servers where users do not log in directly.
2. Deliver is a simple Linux mail delivery utility that is configured in the Imapd configuration files by default.
3. Dovecot’s LDA and Dovecot’s LMTP server are part of the Dovecot IMAP/POP3 server. Dovecot is a lightweight, modern, and configurable mail server.
4. Postfix’s MDA is part of the Postfix MTA software. Postfix is a modern, security-oriented, flexible MTA.
An IMAP or POP3 server handles connections from incoming IMAP or POP3 clients. The server manages client access to the mailboxes and raw mail files so that the email is displayed in a modern way. Most servers and clients support both IMAP and POP3.
POP3 clients connect to the server at specified intervals and download all of a user’s messages without leaving copies on the server by default. POP3 was developed when most people used only one device to access one email account.
IMAP is a newer protocol designed for multi-device users. IMAP clients stay continuously connected to the server and IMAP mailboxes mirror the mailboxes on your server.
IMAP and POP3 both have secure versions (IMAPS and SSL-POP) which use SSL encryption for mail transfer. The most popular IMAP and POP3 servers are:
1. Citadel is an all-in-one mail service that includes mail, calendars, instant messaging, mailing lists, and other collaboration tools. It is open source and geared towards small and medium-sized organizations.
2. Cyrus is a modern, security-oriented IMAP/POP3 server designed to work on sealed servers where users do not log in directly.
3. Dovecot is a lightweight, modern, and configurable mail server.
4. Zimbra is an all-in-one mail service that’s much simpler to install than other options, but less customizable.
To setup your email server, you need to Install and configure the MTA, MDA, and IMAP/POP3 server. To install it on Ubuntu or Debian,
1. Installing Postfix Mail Server
$ sudo apt-get install postfix
During installation, you will be asked to choose the default file configuration for your server. Next, it asks you to select type of mail configuration, choose "Internet Site". Now, enter the fully qualified domain name (FQDN) that you want to use for sending and receiving mails. Once the FQDN set, restart the Postfix mail server:
$ sudo service postfix restart
2. Installing Dovecot
To install it, run the following command:
$ sudo apt-get install dovecot-imapd dovecot-pop3d
During the installation process, you will be asked if you want to create a self-signed SSL certificate, choose Yes. Next, enter your host name to use in the SSL certificate. Next, restart Dovecot service:
$ sudo service dovecot restart