|
|
HP-UX Mailing Services Administrator's Guide: HP-UX 11i v1 and HP-UX 11i v2 > Chapter 1 Mailing
Services OverviewThe Sendmail Utility |
|
Sendmail acts as a post office, to which all messages can be submitted for routing. Sendmail interprets both Internet (that is, user @domain) and UUCP (that is, host !user) styles of addressing. The Sendmail configuration file controls how the addresses are interpreted. Sendmail can rewrite message addresses to conform to standards on many common target networks. For more technical and conceptual information about Sendmail, HP recommends that you read Sendmail, 3rd Edition, by Bryan Costales with Eric Allman, published by O’Reilly and Associates, Inc. Sendmail discusses Sendmail Version 8.12, and some of its features may not be supported by Sendmail 8.11.1. You can also refer to the Sendmail 8.13 Companion by Bryan Costales. For information about using Sendmail with BIND, HP recommends that you read DNS and BIND, by Paul Albitz and Cricket Liu, also published by O’Reilly and Associates, Inc. You can get information about the O’Reilly books (availability, how to order them, and so on) by visiting the O’Reilly Website:
You also can visit the Website for Sendmail:
This section discusses the following topics: A message has three parts: an envelope, a message header, and a message body. The envelope consists of the sender address, recipient address, and routing information shared by programs that create, route, and deliver the message. It is usually not seen directly by either the sender or the recipients of the message. The message header consists of a series of standard text lines used to incorporate address, routing, date, and other information into the message. Header lines may be part of the original message and may also be added or modified by the various mail programs that process the message. Header lines may or may not be used by these programs as envelope information. By default, the first blank line in the message terminates the message header. Everything that follows is the message body and is passed uninterpreted from the sender to the recipient. Sendmail receives messages through any of the following methods:
Sendmail routes messages as follows:
Figure 1-1 “Flow of Mail Through Sendmail” outlines the flow of messages through Sendmail. After Sendmail collects a message, it routes the message to each of the specified recipient addresses. In order to route a message to a particular address, Sendmail must resolve that address to a {delivery agent, host, user} triple. This resolution is based on the rules defined in the Sendmail configuration file, /etc/mail/sendmail.cf. Sendmail invokes a separate delivery agent for each host to which messages are being routed. Some delivery agents can accept multiple users in a given invocation. Others must be invoked separately for each recipient. Delivery agents that HP supports for use with Sendmail include SMTP, UUCP, X.400, and OpenMail. To invoke a delivery agent, Sendmail constructs a command line according to a template in the configuration file. If the delivery agent is specified as IPC, Sendmail does not invoke an external delivery agent. Instead, Sendmail opens a TCP/IP connection to the SMTP server on the specified host and transmits the message using SMTP. If an address resolves to the local mailer, Sendmail looks up the address in its alias database and expands it appropriately if it is found. The aliasing facility or a user’s .forward file can be used to route mail to programs and to files. (Sendmail does not mail directly to programs or files.) Mail to programs is normally piped to the prog mailer (/usr/bin/sh -c), which executes the command specified in the alias or .forward file definition. (You can restrict the programs that can be run through the aliases or .forward files. See “Security” for more information.) Mail to a file is directly appended to the file by Sendmail if certain conditions of ownership and permission are met. After expanding all the aliases, Sendmail routes mail that is addressed to a local user to the local mailer (/usr/bin/rmail), which deposits the message in the user’s mailbox. The installed configuration file, if unmodified, routes mail depending on the syntax of the recipient addresses as described in the following sections. The following forms are recognized as local addresses and are delivered locally:
Addresses of the following forms are recognized as UUCP addresses, where host is not the local host name:
If your host has a direct UUCP connection to the next host in the path, the mail is delivered to that host through UUCP. If not, the message is returned with an error. The supplied configuration file provides detailed instructions for arranging to relay such mail through hosts to which you can connect. RFC 2822-style addresses in any of the following forms, where host is not the local host name, are routed by SMTP over TCP/IP:
If the name server is in use, Sendmail requests mail exchanger (MX) records for the remote host. If there are any, it attempts to deliver the mail to each of them, in the order of preference, until delivery succeeds. Otherwise, Sendmail connects directly to the recipient host and delivers the message. The supplied configuration file interprets address operators with the following precedence:
This means that recipient addresses using mixtures of these operators are resolved as shown in Table 1-3 “How Sendmail Resolves Addresses with Mixed Operators”. Table 1-3 How Sendmail Resolves Addresses with Mixed Operators
The BIND name server, if it is in use on your host, provides MX records. These can be used to notify Sendmail that mail for a particular host can be relayed by another host, if the addressed host is temporarily down or otherwise inaccessible. For information on creating MX records, see HP-UX IP address and Client Management Guide at the URL http://www.docs.hp.com/hpux/netcom/index.html#Internet%20Services. MX records are used only if a message address resolves to an IPC mailer (that is, one that uses SMTP over sockets to perform delivery). Instead of attempting to connect directly to the recipient host, Sendmail first queries the name server, if it is running, for MX records for that host. If the name server returns any answer, Sendmail sorts them in preference order, highest preference (lowest number) first. If the local host appears in the list, the local host and any MX hosts with lower preference (higher numbers) are removed from the list. If any MX hosts remain, Sendmail then tries to connect to each MX host in the list in order, and it delivers the message to the first MX host to which it successfully connects. If that MX host is not the final destination for the message, it is expected that the host will relay the message to its final destination. If Sendmail tries all the MX hosts in the list and fails, the message is returned to the sender with an error message. If you want Sendmail to try to connect to the host to which the message is addressed, uncomment the following line in the /etc/mail/sendmail.cf file:
Sendmail then tries to connect to the host to which the message is addressed, if any of the following conditions occur:
At log level 11 and above, Sendmail logs in the system log the name and Internet address of the MX host (if any) to which it delivered (or attempted to deliver) a message. MX records are used for two main purposes:
In the following example, the name server serving the domain paf.edu has the following MX records configured to provide backup for host bling:
Normally, mail for bling will go directly to bling. However, if bling is down, or if the sending host cannot connect to bling, Sendmail will route mail for bling to wheo. If wheo is also down or unreachable, Sendmail will route the mail to munch. Naturally, for this to be useful, wheo and munch must be able to route mail to bling. Assuming that the host and its mail exchangers see the same MX data from the name server, each host that has MX records should have an MX record for itself, and the preference on its own record should be the highest (that is, the lowest number) in the list. The following example relays messages through a gateway:
Messages addressed to hosts in the nz domain are relayed to the host gw.dcc.nz. HP recommends that you seek permission from the administrators of hosts not under your own control before relaying mail through them. Several possible failures are associated with MX configuration:
Mail queue performance is impacted by the number of entries in the queue directories. Multiple Queue Directories improves mail queue performance in Sendmail. This feature facilitates the parallel processing of mail by spreading process loads across multiple disks, thereby improving the queue performance. UNIX files take a long time to open when entries in the directories exceed 100. In order to use multiple directories, you must supply the QueueDirectory option in the sendmail.cf file with a value ending with *. For example, if you specify the following in the configuration file, all the directories or links to directories that begin with g will be used:
If there are five directories, g1, g2, g3, g4, and g5, Sendmail uses all five directories when the Sendmail daemon is restarted. Mail is randomly assigned to the queue directories. Do not change the queue directory structure when Sendmail is running. You can flush individual mail queues by specifying the following on the command line:
You can use the mailq command to display the mail queue, as shown in the following example:
An efficient queue file-naming system is also being provided in this release. The algorithm used to name files ensures that the names will be unique for 60 years. The queued items can be moved between queues with ease. This section describes the operation of Sendmail servers and clients. Figure 1-2 “Sendmail Client-Server Operation” shows a Sendmail server called mailserv and a Sendmail client called mailclient in the company.com domain. On mailclient, the SENDMAIL_SERVER_NAME in the /etc/rc.config.d/mailservs file is set to mailserv.company.com. user1 is a user on mailclient. Outgoing mail from user1 can be local mail that is intended for any user on mailclient. Local mail is forwarded to mailserv; you specify this by setting the DH macro entry in the /etc/mail/sendmail.cf file on mailclient. (The Sendmail installation script sets the DH macro value to the host specified by SENDMAIL_SERVER_NAME.) Outgoing mail that is not local is sent by mailclient to the remote host using MX records. Because the DM macro entry in the /etc/mail/sendmail.cf file on mailclient is set to mailserv.company.com, mail from user1 appears to be from user1@mailserv.company.com. Because mail sent to remote hosts from user1 is sent from user1@mailserv.company.com, replies to user1’s messages are returned to mailserv. On mailserv, when Sendmail receives mail for user1, it looks up user1 in the aliases database and redirects mail for user1 to user1@mailclient. You can modify Sendmail server and client operations. Most modifications involve changing or re-creating the /etc/mail/sendmail.cf file on the server or client systems. For example, you can define the DM macro on a mail server system. You can also modify the /etc/mail/sendmail.cf file so that the clients relay all outbound mail to the server; this is described in “Modifying the Default Sendmail Configuration File”. By default, Sendmail immediately reports to standard output any errors that occur during the routing or delivery of a message. Sendmail distinguishes between temporary failures and permanent failures. Permanent failures are mail transactions that are unlikely to succeed without the intervention of the sender or a system administrator. For example, mailing to an unknown user is a permanent failure. A delivery failure of the local mailer because the file system is full is also a permanent failure. Temporary failures are mail transactions that might succeed if retried later. For example, an error message connection refused displayed while attempting to connect to a remote SMTP server is a temporary failure, since it probably means that the server is temporarily not running on the remote host. Permanent failures include the following:
In most cases, if message delivery fails permanently on a remote system, mail that includes a transcript of the failed delivery attempt and the undelivered message is returned to the sender. This transcript includes any standard error output from the delivery agent that failed. If Sendmail tries all MX hosts in its preference list and fails to deliver a message, the message is returned to the sender with an error message. For more information, see “Mail Exchanger (MX) Records”. If delivery failed on an alias, and an owner is configured for that alias in the aliases database, Sendmail returns the message and transcript to the alias owner. If the message header contains an Errors-To: header line, Sendmail returns the message and transcript to the address on the Errors-To: line instead of to the sender’s address. If the Postmaster Copy option (option P) is set to a valid address, Sendmail sends a copy of the transcript and failed message (with the message body deleted) to the Postmaster Copy address. If the attempt to return the failed message itself fails, Sendmail returns the message and transcript to the alias postmaster on the local system. The postmaster alias in the default alias file (/usr/newconfig/etc/mail/aliases) resolves to root. If Sendmail is unable to return the message to any of the addresses described previously, as a last resort it appends the error transcript and returned message to the file /var/tmp/dead.letter. Finally, if this fails, Sendmail logs the failure and leaves the original failed message in the mail queue so that a future queue-processing daemon will try to send it. If this fails, an error message is returned again. Messages that fail temporarily are saved in the mail queue and retried later. By default, the mail queue is stored in the directory /var/spool/mqueue. Sendmail saves the message components in two files created in the mail queue directory. The message body is saved in a data file, and the envelope information, the header lines, and the name of the data file are saved in a queue control file. Typically, the Sendmail daemon is run with the -q time_interval option, as in the following example:
In this example, every 30 minutes, Sendmail processes any messages currently in the queue. While processing the queue, Sendmail first creates and sorts a list of the messages in the queue. Sendmail reads the queue control file for each message to collect the preprocessed envelope information, the header lines, and the name of the data file containing the message body. Sendmail then processes the message just as it did when it was originally collected. If Sendmail detects, from the time stamp in a queued message, that the message has been in the mail queue longer than the queue timeout, it returns the message to the sender. The queue timeout is set with the Timeout.queuereturn option in the /etc/mail/sendmail.cf file and, by default, is five days. |
|