108.3 Mail Transfer Agent (MTA) Basics

Weight: 3

Goal: Be aware of MTAs on Linux. Manage forwarding and aliases for local users.

The exam expects awareness of the major MTAs, plus practical knowledge of aliases, forwarding, and the mail queue.


1. What is an MTA?

A Mail Transfer Agent (MTA) is a server program that sends and receives email between machines using SMTP (Simple Mail Transfer Protocol). It is the postal service of the internet.

Three terms often used together:

Term What it does Example
MUA (Mail User Agent) The mail client a user uses to read and write messages. Thunderbird, Outlook, mutt, mail
MTA (Mail Transfer Agent) Moves mail between servers using SMTP. Postfix, Sendmail, Exim, qmail
MDA (Mail Delivery Agent) Delivers mail into the user’s mailbox file. procmail, maildrop, often built into the MTA

A typical flow:

MUA  ───SMTP──►  MTA (sender) ───SMTP──►  MTA (recipient) ──► MDA ──► mailbox

Every Linux system traditionally has a local MTA running so that programs (cron, system warnings, mail from scripts) can send mail — even if no real email actually leaves the machine.


2. The Four MTAs You Must Recognize

The exam lists these four by name. You don’t have to configure them — just know which is which.

Sendmail

Postfix

Exim

qmail

“The sendmail binary”

To make life easier for programs that send mail, all major MTAs provide a /usr/sbin/sendmail command that behaves like the original Sendmail’s submission interface. So whether the system runs Postfix, Exim, or qmail, scripts and tools (cron, PHP’s mail(), etc.) can still call sendmail and it just works.

That’s why the exam says “the sendmail command” — it’s a generic interface, not necessarily the Sendmail MTA.

echo "Subject: Hi
Hello there" | /usr/sbin/sendmail -t alice@example.com

3. Sending Mail from the Command Line: mail / mailx

mail (often a symlink to mailx) is the simple command-line tool for sending and reading mail.

# Send a simple message
echo "Backup completed" | mail -s "Backup OK" root

# With attachment (depends on implementation)
mail -s "Subject" -a /path/to/file.log user@example.com < body.txt

# Read your own mailbox
mail

This is the same command introduced in objective 105.2 (scripting). For the exam, remember:


4. Mail Aliases: /etc/aliases

/etc/aliases redirects mail addressed to a local username to one or more other destinations. It is the standard way to do site-wide redirection.

Format — one alias per line, name: destination:

# /etc/aliases

# Required: redirect root's mail to a real human
root:           alice

# Forward mail to multiple users
sysadmins:      alice, bob, carol

# Forward to an external address
webmaster:      admin@example.com

# Pipe to a program (note the leading | inside the quotes)
support:        "|/usr/local/bin/ticket-import"

# Read recipients from a file
allstaff:       :include:/etc/mail/staff-list

# Redirect to a file (mail is appended to it)
archive:        /var/mail/archive

# Chain: support → helpdesk → multiple users
support:        helpdesk
helpdesk:       alice, bob

Right-hand side options:

Form Meaning
username Deliver to local user.
user@host Deliver to remote address.
/path/file Append message to a file.
|command Pipe message into a command (must be quoted, often with the leading | inside quotes).
:include:/path Read additional recipients from that file.

newaliases — rebuild the database

The MTA doesn’t read /etc/aliases directly at delivery time. It reads a hashed database built from it, usually /etc/aliases.db. After editing /etc/aliases, you must run:

newaliases

On Postfix this is equivalent to postalias /etc/aliases. On Sendmail it runs sendmail -bi. Forgetting newaliases is a classic exam trap.


5. User-Level Forwarding: ~/.forward

A user can redirect their own incoming mail without root’s help by creating a file ~/.forward in their home directory.

Format — one destination per line (same right-hand-side options as /etc/aliases):

# ~/.forward
alice@gmail.com
\alice                            # also keep a local copy (backslash prefix)
"|/usr/local/bin/spam-filter"

Key points:

~/.forward is the per-user counterpart to the system-wide /etc/aliases.


6. The Mail Queue

When an MTA can’t deliver a message immediately (remote server down, etc.), it stores it in a queue and retries later. You can inspect and manage this queue.

Standard commands

mailq                      # show the mail queue (works with all MTAs)
sendmail -bp               # same — equivalent to mailq

Output shows each queued message, its size, age, and recipient.

Postfix-specific tools

postqueue -p               # equivalent of mailq
postqueue -f               # FLUSH the queue (try delivery now)
postsuper -d ALL            # DELETE all messages from the queue
postsuper -d <queue-id>     # delete one message

Sendmail / Exim

For the exam, the universal commands are mailq and sendmail -bp.


7. Mailbox Locations

Where the actual user mail is stored depends on the MTA/MDA, but two formats dominate:

Format Location Structure
mbox /var/mail/<username> or /var/spool/mail/<username> All messages concatenated into a single file.
Maildir ~/Maildir/ (with subdirs new/, cur/, tmp/) One file per message. More robust under concurrency.

You only need to recognize both names — the exam doesn’t go deeper.


8. Quick Reference for the Exam

MTAs to recognize:

Files:

Commands:


9. Likely Exam Questions (Self-Check)

  1. Name the four MTAs the LPIC-102 objective lists. Sendmail, Postfix, Exim, qmail.

  2. What is the difference between an MTA and an MUA? An MTA (Mail Transfer Agent) is a server that transports mail between machines via SMTP. An MUA (Mail User Agent) is the client a user uses to read and compose mail.

  3. What does /usr/sbin/sendmail do on a system running Postfix? It is a compatibility command. Postfix provides its own sendmail binary so that scripts and applications written against the Sendmail interface work unchanged.

  4. Where do system-wide mail aliases live? /etc/aliases.

  5. What command must you run after editing /etc/aliases, and why? newaliases. The MTA reads a binary, hashed database (/etc/aliases.db) built from the text file — it doesn’t see your edits until you rebuild it.

  6. How do you forward all root’s mail to user alice? Add root: alice to /etc/aliases, then run newaliases.

  7. How can a user redirect their own incoming mail without root’s involvement? By creating a ~/.forward file containing the destination address(es).

  8. What is the difference between /etc/aliases and ~/.forward? /etc/aliases is a system-wide file, edited by root, that requires newaliases to take effect. ~/.forward is per-user, lives in the user’s home, and the MTA reads it automatically without needing a database rebuild.

  9. In /etc/aliases, what does this entry mean: support: "|/usr/local/bin/ticket-import"? Every mail addressed to support is piped into the program /usr/local/bin/ticket-import on standard input.

  10. In a .forward file, what does \alice mean? Deliver a copy to the local user alice in addition to the other listed destinations. The backslash prevents further alias expansion.

  11. What command shows the mail queue, regardless of the MTA in use? mailq (equivalent to sendmail -bp).

  12. What is the Postfix command to flush the queue and try to deliver everything now? postqueue -f.

  13. What is the typical location of an mbox mailbox? /var/mail/<username> or /var/spool/mail/<username>.

  14. Where is a Maildir mailbox typically located, and what subdirectories does it contain? Under the user’s home directory, often ~/Maildir/, with three subdirectories: new/, cur/, and tmp/.

  15. Why is it common to alias root to a real user? Cron jobs, system warnings, and many daemons mail root by default. Aliasing root to a human ensures someone actually sees those messages.