108.3 Mail Transfer Agent (MTA) basics
Candidates should be aware of the commonly available MTA programs and be able to perform basic forward and alias configuration on a client host. Other configuration files are not covered.
Key Knowledge Areas
- Create e-mail aliases.
- Configure e-mail forwarding.
- Knowledge of commonly available MTA programs (postfix, sendmail, qmail, exim) (no configuration)
Mail system architecture
Mail systems are built from a number of components as shown in the figure.
Figure 108.3-1: Mail System Architecture
Mail user agents (MUA) are the programs the end-user interacts with directly to compose or to read email. The MUA usually allows the user to organise mail into folders on his local machine. Examples include Kmail, Evolution, pine, mutt, elm, and many others.
Mail transfer agents (MTA) are the programs that perform the "long haul" of mail delivery. They deliver messages to the mail server for the destination domain. MTAs listen on port 25 and use the SMTP (Simple Mail Transfer Protocol) to transfer messages. Usually, an MTA is configured to accept inbound mail destined for one or more "local" domains and to accept outbound mail from a MUA on the local network. MTAs should not be configured to relay mail (that is, to forward it from one remote MTA to another) or to accept mail from remote, unauthenticated MUAs. Such "open relays" provide the perfect cover for a spammer to hide behind, and will likely get your server black-listed.
Historically, sendmail has been the most popular mail transfer agent and it is still widely used. It has a notoriously complex configuration file. Other MTAs include postfix, exim and qmail.
Mail delivery agents (MDA) handle the local delivery of mail. Messages can be delivered to a person, a mailing list, a file, or even to a program. There are several MDAs in use. For example, Postfix can act as an MDA, delivering mail direct to the users' mailboxes. Other MDAs include procmail and the "deliver" component of Dovecot.
Mail access agents (MAA) deliver messages from the mailbox on the mail server to the user's MUA. Two protocols are in common use: POP3 and IMAP. POP3 is popular with Internet Service Providers; usually messages are downloaded from the mail server to the user's local machine. The messages are then deleted from the server so that long-term storage is the responsibility of the user. IMAP is often used by corporate mail servers. With IMAP, the mail server is typically responsible for the long-term storage of a user's mail. Examples of MAAs include imapd, qpopper and dovecot.
Historically, sendmail has been the most widely used MTA. The sendmail script which stops or starts the sendmail daemon is usually located in the /etc/rc.d/init.d/ directory.
The main configuration file for sendmail is /etc/mail/sendmail.cf (or /etc/sendmail.cf). Here you can specify the name of the server as well as the names of the hosts from which and to which mail relay is allowed. The file contains a complex series of rules that govern the re-writing of mail addresses and the selection of a delivery mechanism. Some key options include:
|Cw||the mailer hostname. Can also contain a list of hostnames or domain names the mailer will assume but it is better to use Fw for this|
|Fw||path to the file containing domain names sendmail will receive mail for|
|Ds||address for 'smart host' , this is a mailer that will relay our outgoing mail|
For the LPI certification you do not need to know how to write sendmail.cf rules. In fact, the rules are usually generated using the sendmail.m4 or sendmail.mc macro file to produce a sendmail.cf file by running the command:
m4 sendmail.mc > sendmail.cf
This process is not part of the LPI objectives.
Sendmail uses the file /etc/mail/local-host-names to determine which mail domains it should receive mail for. This file must list all the machines and domain names for which this server will handle (incoming) mail. If you change the file you must send sendmail a HUP signal for it to notice the change.
Sendmail usually runs as a daemon listening on port 25 for SMTP messages. It can also be invoked from the command line to inject mail messages or to examine and administer the mail queues. Alternative MTAs such as postfix emulate the sendmail behaviour by providing a compatible command-line interface. This includes the commands mailq, newaliases, and the sendmail command itself.
Aliases and mail forwarding
Aliases allow mail to be re-routed either by the system administrator or by individual users. Aliases let you define mailing lists or allow users to be referred to by more than one name.
The file /etc/aliases defines system-wide aliases. (Actually, the path name to this file is specified by the "AliasFile" parameter in sendmail.cf so it might be different on your system. /etc/mail/aliases is a common alternative location.) Each line in this file contains two fields as follows:
alias: address_1,address_2,address_3, ...
The first field is the name to alias. The aliased addresses can be:
A local user name(example: benjamin)
A local file name(example: /tmp/maildrop)
A command(example: | someprogram)
A simple use of aliases is to define an alternative mail name for a user. For example if the user Fred Flintstone has a Linux account called fred, a line in /etc/aliases such as:
will allow fred to receive mail with the name flintstone.
You can even redirect mail to a remote domain with an alias like this:
(but be aware that if there is a local account called flintstone, this line would prevent him from receiving any email!)
You can also use aliases to define mailing lists, for example:
authors: tom, dick, firstname.lastname@example.org
For other options see the manpage aliases(5).
When changes to the /etc/aliases file are made the newaliases command must be run to rebuild the alias database /etc/aliases.db. This is the file that sendmail consults at run time.
Individual users can create mail alias by placing entries into the file ~/.forward.
This file consists of a list of comma-separated addresses on a single line, or several entries on separate lines. For example, a user might choose to forward his email to some other site, and to save it in a local file, with an entry in ~/.forward like this:
The Mail Queues
When mail is accepted by a mail server it is placed in a message store (shown as "mailbox" in the figure above). There are two formats in use for the message store. The oldest (and simplest) is the mbox format. Using this format, each user's mail is stored in a single file (usually /var/spool/mail/fred for the user fred). This is a plain text file; messages are simply appended to the file when they arrive. The beginning of each message is marked by a "From" line.
An alternative format for the message store is the maildir format. A maildir message store has three directories called tmp, new, and cur. These directories are usually in a mail subdirectory within the user's home directory. The maildir message format stores each message in a separate file.
Depending on the Mail User Agent used (mutt, pine, elm ...), a user can either store these messages in his home directory or download them on another machine.
All outgoing mail is spooled in /var/spool/mqueue. If the network is down or very slow, or if many messages are being sent, then mail accumulates in the mail spool queue. You can query the queue with the mailq utility or sendmail –bp.
An administrator can flush the server’s queue with sendmail –q.
Sendmail is currently the default MTA in RedHat, Fedora and many other Linux distributions. However there are a number of MTAs that can be used as an alternative. These include:
Qmail is an MTA written by Dan Bernstein as a "secure, reliable, efficient, simple mail transfer agent". Although originally qmail did not have an open licence it is now open source and may be freely redistributed. Like most MTAs, qmail honours the /etc/aliases file and provides the newaliases command to process it. Related tools for managing the qmail message queue include qmail-read, qmail-stat and qmhandle.
Exim is an MTA developed at the University of Cambridge. It runs on UNIX and Linux and is available under a GPL licence.
Postfix is an MTA written by Wietse Venema. It is distributed under the IBM public licence vsn 1.0. Postfix is highly modular. Each operation is performed by a separate executable which runs with only the minimum privilege needed to do the job. Individual components are started up by the master daemon; this is configured by the file /etc/postfix/master.cf. All the configuration of postfix is done in /etc/postfix; the main configuration file is main.cf. The postconf command is used to examine and modify the parameters defined in this file. Postfix has a good reputation for security and is relatively straightforward to configure. After sendmail it is probably the most popular MTA and is used by default in Ubuntu.
Mail delivery and DNS
MTAs need to find the mail servers for the domains they are trying to deliver mail to. They do this by querying DNS for an MX (mail exchanger) record for the domain they are trying to reach. For example if an MTA is delivering mail to email@example.com it will query DNS for an MX record for the example.com domain. This record indicates the name of the domain's mail server. If you are configuring a mail server, you will need to add (or ask your ISP to add) the DNS MX record for your domain to point to your machine.
Finally in order to use a domain name as a valid email address an MX record needs to be added on an authoritative name server for your domain (usually your ISP).
You will also need to add the domain name to /etc/mail/local-host-names
The following is a partial list of the used files, terms and utilities:* ~/.forward
- sendmail emulation layer commands