Outbound email When you send email, the MUA passes the email to sendmail, which creates in the /var/spool/mqueue (mail queue) directory two files that hold the message while sendmail processes it. To create a unique filename for a particular piece of email, sendmail generates a random string and uses that string in filenames pertaining to the email. The sendmail daemon stores the body of the message in a file named df (data file) followed by the generated string. It stores the headers and other information in a file named qf (queue file) followed by the generated string. If a delivery error occurs, sendmail creates a temporary copy of the message that it stores in a file whose name starts with tf (temporary file) and logs errors in a file whose name starts xf. Once an email has been sent successfully, sendmail removes all files pertaining to that email from /var/spool/mqueue.
Incoming email By default, the MDA stores incoming messages in users' files in the mail spool directory, /var/spool/mail, in mbox format. Within this directory, each user has a mail file named with the user's username. Mail remains in these files until it is collected, typically by an MUA. Once an MUA collects the mail from the mail spool, the MUA stores the mail as directed by the user, usually in the user's home directory hierarchy.
mbox versus maildir The mbox format stores all messages for a user in a single file. To prevent corruption, the file must be locked while a process is adding messages to or deleting messages from the file; you cannot delete a message at the same time the MTA is adding messages. A competing format, maildir, stores each message in a separate file. This format does not use locks, allowing an MUA to read and delete messages at the same time as new mail is delivered. In addition, the maildir format is better able to handle larger mailboxes. The downside is that the maildir format adds overhead when you are using a protocol such as IMAP to check messages. The dovecot package supports both mbox and maildir formats. Qmail (page 652), a sendmail alternative, uses maildir-format mailboxes. Mail logsThe sendmail daemon stores log messages in /var/log/maillog. Other mail servers, such as the dovecot imap-login and pop3-login daemons, may also log information to this file. Following is a sample log entry:
/var/log/maillog # cat/var/log/maillog ... Mar 3 16:25:33 MACHINENAME sendmail[7225]: i23GPXvm007224: to=<user@localhost.localdomain>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30514, dsn=2.0.0, stat=Sent Each log entry starts with a timestamp, the name of the system sending the email, the name of the mail server (sendmail), and a unique identification number. The address of the recipient follows the to= label and the address of the sender follows ctladdr=. Additional fields provide the name of the mailer and the time it took to send the message. If a message is sent correctly, the stat= label is followed by Sent. A message is marked Sent when sendmail sends it; Sent does not indicate that the message has been delivered. If a message is not delivered because an error occurred farther down the line, the sender usually receives an email saying that it was not delivered and giving a reason why. If you send and receive a lot of email, the maillog file can grow quite large. The syslog logrotate (page 559) entry is set up to archive and rotate the maillog files regularly. Aliases and ForwardingThree files can forward email: .forward (page 634), aliases (discussed next), and virtusertable (page 640). Table 20-1 on page 640 compares the three files.
/etc/aliases Most of the time when you send email, it goes to a specific person; the recipient, user@system, maps to a specific, real user on the specified system. Sometimes you may want email to go to a class of users and not to a specific recipient. Examples of classes of users include postmaster, webmaster, root, and tech_support. Different users may receive this email at different times or the email may be answered by a group of users. You can use the /etc/aliases file to map inbound addresses to local users, files, commands, and remote addresses. Each line in /etc/aliases contains the name of a local pseudouser, followed by a colon, whitespace, and a comma-separated list of destinations. The default installation includes a number of aliases that redirect messages for certain pseudousers to root. These have the form system: root Sending messages to the root account is a good way of making them easy to review. However, because root's email is rarely checked, you may want to send copies to a real user. The following line forwards mail sent to abuse on the local system to root and alex: abuse: root, alex You can create simple mailing lists with this type of alias. For example, the following alias sends copies of all email sent to admin on the local system to several users, including Zach, who is on a different system: admin: sam, helen, mark, zach@tcorp.com You can direct email to a file by specifying an absolute pathname in place of a destination address. The following alias, which is quite popular among less conscientious system administrators, redirects email sent to complaints to /dev/null (page 448), where they disappear: complaints: /dev/null You can also send email to standard input of a command by preceding the command with a pipe character (|). This technique is commonly used with mailing list software such as Mailman (page 646). For each list it maintains, Mailman has entries, such as the following entry for mylist, in the aliases file: mylist: "|/usr/lib/mailman/mail/mailman post mylist"
newaliases After you edit /etc/aliases, you must either run newaliases as root or restart sendmail to recreate the aliases.db file that sendmail reads.
praliases You can use praliases to list aliases currently loaded by sendmail: # /usr/sbin/praliases| head-5 postmaster:root daemon:root adm:root lp:root shutdown:root
~/.forward Systemwide aliases are useful in many cases, but nonroot users cannot make or change them. Sometimes you may want to forward your own mail: Maybe you want mail from several systems to go to one address or perhaps you just want to forward your mail while you are working at another office for a week. The ~/.forward file allows ordinary users to forward their email. Lines in a .forward file are the same as the right column of the aliases file explained previously: Destinations are listed one per line and can be a local user, a remote email address, a filename, or a command preceded by a pipe character (|). Mail that you forward does not go to your local mailbox. If you want to forward mail and keep a copy in your local mailbox, you must specify your local username preceded by a backslash to prevent an infinite loop. The following example sends Sam's email to himself on the local system and on the system at tcorp.com: $ cat ~sam/.forward sams@tcorp.com \sam Related Programs
sendmail The sendmail package includes several programs. The primary program, sendmail, reads from standard input and sends an email to the recipient specified by its argument. You can use sendmail from the command line to check that the mail delivery system is working and to email the output of scripts. See page 631 for an example.
mailq The mailq utility displays the status of the outgoing mail queue and normally reports there are no messages in the queue. Messages in the queue usually indicate a problem with the local or remote sendmail configuration or a network problem. # /usr/bin/mailq /var/spool/mqueue is empty Total requests: 0
mailstats The mailstats utility reports on the number and sizes of messages sendmail has sent and received since the date it displays on the first line: # /usr/sbin/mailstats Statistics from Sat Dec 24 16:02:34 2005 M msgsfr bytes_from msgsto bytes_to msgsrej msgsdis Mailer 0 0 0K 17181 103904K 0 0 prog 4 368386 4216614K 136456 1568314K 20616 0 esmtp 9 226151 26101362K 479025 12776528K 4590 0 local ============================================================ T 594537 30317976K 632662 14448746K 25206 0 C 694638 499700 146185 In the preceding output, each mailer is identified by the first column, which displays the mailer number, and by the last column, which displays the name of the mailer. The second through fifth columns display the number and total sizes of messages sent and received by the mailer. The sixth and seventh columns display the number of messages rejected and discarded respectively. The row that starts with T lists the column totals, and the row that starts with C lists the number of TCP connections. |