Email is the method computers use to send and receive messages across a network, and it relies on three core protocols: SMTP, IMAP, and POP3. Understanding these protocols is non-negotiable for passing the LPIC-2 exam, because the exam directly asks you to configure, troubleshoot, and explain how email flows through a Linux mail server.
Jump to a section
A simple way to picture Email Services (SMTP, IMAP, POP3)
A small village with one central post office and no home mail delivery.
Everyone in the village uses this post office to send and receive letters. When you write a letter to a friend in the next village, you put it in an envelope, write the address, and drop it into the bright red 'Outgoing Mail' slot at the post office. That slot is your SMTP server – it only handles sending mail out of the village. The postmaster then passes your envelope to a mail coach that travels the road to the next village. The coach is the Message Transfer Agent (MTA), and the road is the internet.
The recipient's village also has a post office. Your friend doesn't wait at the post office all day – they have a private wooden box inside the building with their name on it. They visit the post office, unlock their box using their key (their password), and collect the letters that have been sorted and placed there by the postmaster. If they use the 'take everything home' method, they pull all letters out at once and their box is now empty – that is POP3. If they use the 'peek or read one at a time' method, they open a letter inside the box, read it, but leave it there for later – that is IMAP. With IMAP, they can also decide to leave a letter in the box and take a copy home, so the box always stays the central repository.
The postmaster routes incoming letters into the correct box using the name on the envelope – that is the Mail Delivery Agent (MDA). If your friend switches to a new wooden box, their old letters can stay in the old box (POP3) or be moved to the new box (IMAP). The entire system works because everyone agrees on the same rules: which slot to use for outgoing mail, how to address envelopes, and what keys open which boxes.
Email services are built on a client-server model where messages travel from sender to recipient using a set of standard rules called protocols. A protocol is simply an agreed-upon language that computers speak to each other – think of it like the handshake and conversation etiquette you use when meeting someone new.
The first protocol to know is SMTP, which stands for Simple Mail Transfer Protocol. SMTP is the protocol used to send email from a client (like Thunderbird or Outlook) to a mail server, and also from one mail server to another. When you hit 'Send' on an email, your email client contacts your outgoing mail server using SMTP on port 25 (traditionally) or port 587 (submission, which requires authentication). The SMTP server looks at the recipient's domain (the part after the @ sign) and uses DNS, the Domain Name System, to find the mail server responsible for that domain. DNS works like a phonebook – it translates a domain name like 'example.com' into an IP address like '192.0.2.10' where the mail server lives. The sending server then hands the message off to the receiving server using SMTP again, and the receiving server works out which local mailbox should receive the email.
Now, once the email lands on the recipient's mail server, the recipient needs a way to fetch it. This is where IMAP and POP3 come in. These are Mail Access Protocols – they let a client program retrieve email from a server.
POP3, or Post Office Protocol version 3, is the older, simpler method. When you check your email with POP3, the client connects to the server, downloads all new messages to your device, and then (by default) deletes them from the server. This means your email lives only on the device you checked it on. POP3 uses port 110 for plaintext connections or port 995 for encrypted connections (POP3S). It is like going to the post office, taking all your letters home, and the post office then empties your box. Great if you only use one device, but a problem if you also check email on your phone – you will miss the messages already downloaded to your laptop.
IMAP, or Internet Message Access Protocol, is the modern alternative. With IMAP, your client connects to the server but keeps the messages stored on the server. You can view headers, read parts of a message, or download the whole thing – but the original stays on the server until you explicitly delete it. This means your email looks the same whether you check it from your phone, laptop, or tablet. IMAP uses port 143 for plaintext or port 993 for encrypted connections (IMAPS). It also supports creating folders and organising messages directly on the server, so you can have an 'Inbox' folder, a 'Sent' folder, and a 'Spam' folder that are synchronised across all your devices.
The key distinction is that SMTP is a push protocol – it pushes messages from client to server and server to server. IMAP and POP3 are pull protocols – they pull messages from the server to the client. SMTP handles the journey from sender to the recipient's server. IMAP or POP3 then handles the final leg from that server to the recipient's device.
In a typical Linux mail server setup, you run multiple pieces of software:
MTA (Mail Transfer Agent): Software like Postfix or Exim that uses SMTP to transfer messages between servers.
MDA (Mail Delivery Agent): Software like Dovecot's LMTP that accepts the message from the MTA and drops it into the correct user's mailbox file or database.
MRA (Mail Retrieval Agent): Software like Dovecot or UW-IMAP that provides IMAP and POP3 services so clients can fetch mail.
Port numbers matter for the exam. Common port use:
Port 25: SMTP (historically for server-to-server transfer, often blocked by ISPs to reduce spam)
Port 587: SMTP Submission (used by clients to send mail, requires authentication)
Port 465: SMTP over SSL (a deprecated but still used variant)
Port 110: POP3
Port 995: POP3S (POP3 over SSL/TLS)
Port 143: IMAP
Port 993: IMAPS (IMAP over SSL/TLS)
1. Client Composes and Sends
The sender's email client (MUA) composes the message and connects to the outgoing SMTP server (usually on port 587). The client authenticates with the server using a username and password. The server checks the sender's credentials and accepts the message for delivery.
2. SMTP Server Looks Up Recipient
The sending SMTP server analyses the recipient's domain (e.g., 'example.com'). It performs a DNS query for MX (Mail Exchange) records to find the hostname of the receiving mail server. DNS returns the server name (e.g., 'mail.example.com'), and then an A or AAAA record resolves that to an IP address.
3. Message Transferred Between Servers
The sending server establishes an SMTP connection (usually on port 25) to the receiving server identified in step 2. It transmits the entire message (headers and body) using SMTP commands such as HELO/EHLO, MAIL FROM, RCPT TO, and DATA. The receiving server accepts or rejects the message.
4. MDA Delivers to Local Mailbox
If the message is addressed to a local user on the receiving server, the MTA hands the message to an MDA like Dovecot's LMTP (Local Mail Transfer Protocol). The MDA places the message into the correct user's mailbox, which is typically a Maildir directory (e.g., /home/user/Maildir/new/) or an mbox file.
5. Client Fetches via IMAP or POP3
The recipient's email client connects to the MRA (e.g., Dovecot) on port 993 (IMAPS) or 995 (POP3S) using their credentials. With IMAP, the client requests a list of folders and new messages; with POP3, the client downloads all waiting messages, often deleting them from the server in the process. The user reads the email on their device.
You are the junior Linux administrator at a mid-sized company called GreenLeaf Organics, which has about 200 employees. Your manager asks you to set up a mail server for the company domain 'greenleaforganics.com' on a brand-new Ubuntu server. The company needs employees to send and receive email using their company address, and they want to check email from both their office desktops and their mobile phones.
Your first task is to install and configure Postfix as the MTA. Postfix will be the software that listens on port 25 for incoming mail from the internet, and also listens on port 587 for authenticated submissions from your users' email clients. You edit the main.cf configuration file in /etc/postfix/ to set the mydomain parameter to 'greenleaforganics.com' and the myorigin parameter to 'greenleaforganics.com', so outgoing mail appears to come from the correct domain. You also set inet_interfaces to 'all' so the server listens for mail from both local and external networks.
Next, you need to configure Dovecot as both the MDA and the MRA. Dovecot handles delivering mail to users' mailboxes using the LMTP protocol (Local Mail Transfer Protocol) and also provides IMAP and POP3 services. For modern, synchronised email, you choose IMAP over POP3. You install dovecot-imapd and dovecot-pop3d packages. In the Dovecot configuration files (typically in /etc/dovecot/), you set: - mail_location = maildir:~/Maildir (this tells Dovecot to store each user's mail in Maildir format, which is a directory structure where each message is a separate file – more reliable than the older mbox single-file format) - protocols = imap pop3 lmtp (to enable both IMAP and POP3 alongside LMTP) - ssl = required (to force all connections to use encryption)
You generate a self-signed SSL certificate and key using OpenSSL, and point Dovecot to them with the ssl_cert and ssl_key parameters. For production, you would use a certificate from a trusted Certificate Authority like Let's Encrypt.
Now, you create user accounts for each employee using standard Linux user accounts (useradd), and set their mail directories. When Sally from Sales sends an email to Bob in Operations, here is the step-by-step journey: 1. Sally's Outlook (her MUA, or Mail User Agent) connects to Postfix on port 587 using SMTP and authenticates with her username and password. 2. Postfix receives the message and queues it for delivery. It looks up Bob's domain (greenleaforganics.com) using DNS MX records (Mail Exchange records) – Postfix finds the IP address of your server. 3. Since the destination is local, Postfix does not send the message over the internet. Instead, it hands the message to Dovecot's LMTP service, which delivers it to Bob's Maildir directory (e.g., /home/bob/Maildir/new/). 4. Bob opens his phone's email app, which connects to Dovecot on port 993 (IMAPS). He enters his username and password, and Dovecot authenticates him using PAM (Pluggable Authentication Modules) – the same system that validates his Linux login. 5. Dovecot lists the contents of Bob's Maildir/new folder, showing the new message from Sally. Bob taps to read it, and the email content is transmitted down to his phone via the IMAP protocol. 6. Later, Bob logs into his desktop Outlook. Because IMAP keeps all messages on the server, his desktop reads the same messages – no duplicates, no missing emails. If he deletes the message on his desktop, the server marks it as deleted, and his phone's IMAP client reflects that change automatically.
Your daily tasks as the admin include:
Checking mail logs in /var/log/mail.log for bounced messages or delivery delays.
Monitoring disk usage because IMAP keeps all email on the server, so mailboxes can grow very large.
Setting mailbox size quotas using Dovecot's quota plugin to prevent any single user filling the drive.
Configuring spam filtering with tools like SpamAssassin, which integrates with Postfix to mark or reject spam before delivery.
Backing up the Maildir directories regularly – users expect their email to survive a server crash.
LPIC-2 exam objective 201.5 is strictly focused on the configuration and operation of SMTP, IMAP, and POP3 on a Linux system. The exam will not ask you about webmail clients like Roundcube; it tests the underlying server software.
The exam loves to test your knowledge of port numbers. You must memorise:
Port 25: SMTP (server-to-server)
Port 587: SMTP Submission (client-to-server, authenticated)
Port 465: SMTP over SSL (deprecated but recognised)
Port 110: POP3
Port 995: POP3 over SSL
Port 143: IMAP
Port 993: IMAP over SSL
Common trap: The exam might present a scenario where you need to choose between port 25 and port 587 for client submission. Remember: port 25 is traditionally for server-to-server relay and is often blocked by residential ISPs to prevent spam. Port 587 is the standard for authenticated client submission. Many exams will also test that port 465 is officially deprecated but still in widespread use.
Another major focus area is understanding the difference between MTA, MDA, and MUA. The exam will give you a list of tasks (e.g., 'received mail from the internet', 'places mail into the user's mailbox', 'the user's email client') and ask you to match each to the correct component. Know that:
MTA (like Postfix, Exim, Sendmail) is responsible for transferring mail between servers.
MDA (like Dovecot's LMTP or procmail) delivers mail to the local mailbox.
MUA (like Thunderbird, Outlook, mutt) is the client software the user interacts with.
Configuration file locations are critical. Postfix's main configuration file is /etc/postfix/main.cf, and its aliases file is /etc/aliases (which maps local usernames to other addresses or to a mailbox). The exam may test the fact that after editing /etc/aliases, you must run the 'newaliases' command to rebuild the hash database, otherwise the changes are not effective.
Dovecot configuration files are in /etc/dovecot/, with the main file being /etc/dovecot/dovecot.conf and individual protocol configurations in /etc/dovecot/conf.d/. The exam expects you to know that Dovecot can authenticate using PAM (Pluggable Authentication Modules) – meaning users authenticate with their Linux username and password – or using a separate password database.
A common trap question: 'Which protocol should you use to allow a user to access their email from multiple devices while keeping the messages on the server?' The answer is IMAP, because POP3 by default downloads and deletes messages. Another trap: 'What is the difference between SMTP and IMAP?' The correct answer is that SMTP is used for sending email, and IMAP is used for retrieving email from a server.
The exam may ask you to identify the correct command to view mail queue status on a Postfix server. The command is 'mailq' or 'postqueue -p'. To flush (attempt to deliver) the queued messages, use 'postqueue -f' or 'sendmail -q'.
LDAP (Lightweight Directory Access Protocol) integration is sometimes tested – Dovecot and Postfix can both be configured to look up user information (mailbox location, aliases) from an LDAP directory. This is more advanced, but the exam may present a scenario where you need to enable LDAP lookups in the configuration.
SMTP (Simple Mail Transfer Protocol) uses ports 25 (relay) and 587 (client submission) to send email between servers and from clients to servers.
IMAP (Internet Message Access Protocol) stores all email on the server, allowing synchronised access from multiple devices using ports 143 or 993 (IMAPS).
POP3 (Post Office Protocol version 3) downloads email to one device and deletes it from the server unless configured otherwise, using ports 110 or 995.
Postfix's main configuration file is /etc/postfix/main.cf, and its aliases are stored in /etc/aliases, processed by the newaliases command.
Dovecot can act as both an MDA (via LMTP) and an MRA (providing IMAP and POP3 services), with configuration files in /etc/dovecot/.
The mailq command and postqueue -p show the Postfix mail queue, and postqueue -f forces a queue flush attempt.
LDAP integration allows both Postfix and Dovecot to look up user mailboxes and aliases from a central directory, reducing manual user management.
Secure connections (TLS) are essential for email to prevent eavesdropping; configure SSL certificates for both Postfix and Dovecot.
These come up on the exam all the time. Here's how to tell them apart.
SMTP
Used for sending email from client to server and server to server
Operates as a push protocol that pushes messages forward
Uses ports 25 (relay) and 587 (submission)
IMAP
Used for retrieving email from the server to the client
Operates as a pull protocol that fetches messages on demand
Uses ports 143 (plain) and 993 (SSL)
IMAP
Keeps all messages on the server by default
Allows synchronisation across multiple devices
Supports server-side folders and subfolders
POP3
Downloads messages to one device and deletes from server by default
Designed for single-device access with limited synchronisation
Only has an inbox; no server-side folder management
Postfix (MTA)
Handles SMTP for sending and receiving mail between servers
Main configuration file is /etc/postfix/main.cf
Uses the queue directory /var/spool/postfix/ for pending messages
Dovecot (MRA/MDA)
Provides IMAP and POP3 services for client access
Main configuration files are in /etc/dovecot/
Manages mailbox storage in Maildir or mbox format
Mistake
SMTP is a protocol for both sending and receiving email to your inbox.
Correct
SMTP is only used for sending email and for relaying mail between servers. Retrieving email from your inbox is done by IMAP or POP3.
People hear 'email protocol' and think one protocol does everything, but email uses separate protocols for separate legs of the journey.
Mistake
POP3 and IMAP both store all email on the server permanently.
Correct
POP3 typically downloads and deletes messages from the server, while IMAP keeps messages on the server and synchronises state across clients.
Beginners assume 'access protocol' means the same behaviour, but the design philosophy is completely different, and the default settings differ.
Mistake
Port 25 is the only port SMTP uses, and it is always the correct choice for client submission.
Correct
Port 25 is used for server-to-server SMTP relay. Port 587 is the standard for client submission because it requires authentication and is less likely to be blocked.
Historically, clients used port 25, but modern best practices and ISP policies have moved submission to port 587. The exam tests this difference.
Mistake
Once a message arrives on the mail server, the user's device is immediately notified and the email is pushed to them.
Correct
Email is not pushed to clients. The client must actively poll the server using IMAP or POP3 to check for new messages, or use IMAP IDLE extension for near-instant notification.
People are used to instant messaging apps that push; email is inherently a pull protocol at the final delivery stage.
Mistake
You must run a separate DNS server to use email; otherwise email won't work.
Correct
You do not need to run your own DNS server; you only need to configure MX records with your domain registrar or hosting provider and ensure your mail server resolves domains externally.
Configuring a mail server often involves DNS, but beginners confuse 'making changes to DNS records' with 'running a DNS server', which is a different service.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
SMTP is like the postal service that takes your letter from your house to the post office and then to the recipient's post office. IMAP and POP3 are like two different ways the recipient can pick up their mail from the post office – IMAP leaves a copy at the post office so you can check it from anywhere, while POP3 picks it up and takes it home permanently.
Port 25 is historically used for server-to-server SMTP traffic. Many residential ISPs block port 25 to prevent home users from running spam-sending servers. Legitimate client submission is supposed to use port 587, which is open and requires authentication.
Use IMAP if you check email from multiple devices (phone, laptop, work PC) and want the same inbox view everywhere. Use POP3 only if you check email from a single device and want to keep your server storage free.
Run the command 'mailq' or 'postqueue -p' from the terminal. This shows all messages currently waiting to be delivered, along with their queue ID, size, sender, and recipient.
Postfix primary configuration file is /etc/postfix/main.cf. Other important files include /etc/postfix/master.cf (for service settings) and /etc/aliases (for local address aliases).
Technically yes, but it will be very limited. Modern email requires DNS MX records so other mail servers know where to deliver messages. Without a domain, you can only send mail that other servers will likely reject as spam.
You've finished Email Services (SMTP, IMAP, POP3). Continue through the LPIC-2 study guide to build a complete picture of the exam.
Done with this chapter?