The MTA Program sendmail

250 Ok ♦ QUIT ♦ 221 apollo.ph.myschool.scps.edu closing connection ♦ The last line simply confirms that the e−mail message was successfully delivered: misapollo.ph.myschool.scps.edu… Sent ♦ •

20.1.2 The MTA Program sendmail

The central point of a UNIX e−mail system is the MTA program sendmail; consequently a major part of the overall text is related to sendmail, and more specifically to the sendmail administration. 20.1.2.1 The sendmail Daemon The sendmail daemon runs nonstop on each host that is intended to fully support e−mail. The sendmail daemon listens on port 25 and processes incoming e−mail. The daemon is invoked during system startup from an rc initialization script file, usually executing the following, or a similar command sequence: if [ −f usrlibsendmail −a −f etcsendmail.cf ]; then cd varspoolmqueue; rm −f nf lf usrlibsendmail −bd −q1h; echo −n sendmail fi The rc script first checks for the existence of the sendmail program and its configuration file etcsendmail.cf. If both are found, the mail queue directory is checked and cleared of any possible remained nfs or locked file found there; it is possible that the system went down while the mail queue was being processed, so unprocessed files may have been inadvertently left behind. They must be removed during system booting to make a place for their reprocessing, as well as for new files. Next, the script starts sendmail with two command line options. The option −bd tells sendmail to run as a daemon, causing sendmail to listen nonstop to port 25 for incoming e−mail. The −q option determines how often the mail queue is processed; for most systems a setting of 1h one hour is a good choice. For larger mailhosts mail servers more frequent mail queue processing could be more appropriate; 30 minutes −q30m or even 15 minutes −q15m could be better choices. This time relates only to the mail queue processing; an e−mail received on port 25 is processed immediately, and only if it fails to be delivered is the e−mail put in the mail queue for later reprocessing. The sendmail daemon runs as long as the system is alive. However, once it becomes too busy, the sendmail daemon will spawn another daemondaemons to help in e−mail processing. Child daemons will exit upon completing their tasks, but the parent daemon continues to run even if it is idle. 20.1.2.2 The sendmail Command sendmail is actually a versatile and powerful UNIX command that can be executed from the command line at any time. The daemon option −bd is only one of many possible options. sendmail can also be invoked to complete a single job, as with any other UNIX command; this is 464 For a better understanding of sendmail, the main program characteristics are summarized below: sendmail sends a message to one or more people, routing the message over networks as needed. sendmail does internetwork forwarding as necessary to deliver the message to the correct place. • sendmail is not intended as a user interface routine; other MUA programs provide user−friendly front ends. sendmail is used only to deliver preformatted messages. With no flags, sendmail reads its standard input up to an EOF or a line with a single dot, and sends a copy of the letter message found there to the address listed. It determines the way to send the message based on the syntax and contents of the addresses. • On the senders side, the recipients address is looked up in the local aliases file or by using NIS, and aliased appropriately. In addition, if there is a .forward file in the recipients home directory, sendmail forwards a copy of each message to the list of recipients that the file contains. Preceding the address with a backslash can prevent aliasing. Normally, the sender is not included in alias expansions for example, if john sends to group, and group includes john in the expansion, then the e−mail will not be forwarded to john. • sendmail can route mail directly to other known hosts in a network. The list of hosts to which mail is directly sent depends on the sendmail configuration, but could also be maintained by certain related files. • The format of the sendmail command is: usrlibsendmail [ option ] Where some of the options are: Option Action −bd Run as a daemon, waiting for incoming SMTP connections. −bi Initialize the alias database. −bm Deliver mail in the usual way default. −bp Print a summary of the mail queue and list all mails currently in the queue. −bt Run in address test mode. This mode reads addresses and shows the steps in parsing, and it is used for debugging configuration address parsing rules. −bv Verify names only — do not try to collect or deliver a message. Verify mode is normally used for validating users or mailing lists. −bz Create the configuration freeze file. −n Do not do aliasing. −hN Set the hop count to N. The hop count is incremented every time the mail is processed; when it reaches a limit, the mail is returned with an error message. −q [time] Process saved messages in the queue at given intervals. If time is omitted, process the queue once. time is given as a tagged number, where s is seconds, m is minutes, h is hours, d is days, and w is weeks. For example, −q1h30m or −q90m would both set the timeout to one hour thirty minutes. −t Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for people to send to, the Bcc: line will be deleted before transmission, and any address in the argument list will be suppressed. −v Verbose mode, alias expansions will be announced; SMTP dialogue presented, etc. • 465 etcaliases ASCII data for alias names alternatively etcmailaliases etcsendmail.cf The configuration file etcsendmail.fc The frozen configuration file v etcsendmail.st Collected statistics usrlibmailhosts A list of hosts to which e−mail can be sent directly usrlibsendmail.hf The help file varspoolmqueue Temporary files and queued mail HOME.forward A list of recipients for forwarding messages user based usrbinmail To deliver local mail usrsbinmailx To deliver local mail alternatively Note: Except for etcsendmail.cf, the actual pathnames are all specified in etcsendmail.cf; the pathnames presented here are only approximations. For new sendmail releases, the configuration file is moved into etcmailsendmail.cf. sendmail s processing of an incoming e−mail regardless of whether it is coming from a local MUA program or a remote sendmail is based on the listed files. The significance of the files varies, but certainly the most important file is the sendmail configuration file etcsendmail.cf — this file will be discussed in greater detail later. However, some other files, such as the global mail aliases file, personal mail forwarding files, the frozen sendmail configuration file, as well as delivery programs, mailers, deserve some attention too. Let us start with them. 20.1.2.3 Other sendmail Constituents To fully respond to such a demanding task, sendmail relies on other related programs and files, which are briefly summarized in the following material.

20.1.2.3.1 Global Mail Aliases

The global mail aliases file etcaliases sometimes linked to etcmailaliases provides, on the system level: Alternate names nicknames for individual local users • Forwarding of mail to other hosts • Mailing lists • The basic format of an entry in the etcaliases file is: alias: recipient[, recipient, …] where alias The name to which the e−mail is addressed recipient Another local user name, the name of another alias, or a full e−mail address containing both a user name and a host name this enables forwarding to a remote 466 Aliases are widely used to specify individual users as nicknames for special names like postmaster, hostmaster, or root, and to deliver e−mail to the real users who do these jobs. They can also be used to implement simplified e−mail addressing. Without them, the concept of sendmail would definitely not be so powerful; they play a central role in e−mail delivery within todays Intranet networks. An example of the aliases file follows; there is no need for additional comments. cat etcaliases Aliases can have any mix of upper and lower case on the left−hand side, but the right−hand side should be proper case usually lower The program newaliases will need to be run after NOTE this file is updated for any changes to show through to sendmail. aliases 2.30 SMI Following alias is required by the mail protocol, RFC 822 Set it to the address of a HUMAN who deals with this systems mail problems. Postmaster: root Alias for mailer daemon; returned messages from our MAILER−DAEMON should be routed to our local Postmaster. MAILER−DAEMON: postmaster Aliases to handle mail to programs or files, eg news or vacation decode: | usrbinuudecode nobody: devnull Sample aliases: Alias for distribution list, members specified here: staff:wnj,mosher,sam,ecc,mckusick,sklower,olson,rwhernie Alias for distribution list, members specified elsewhere: keyboards: :include:usrjfarrellkeyboards.list Alias for a person, so they can receive mail by several names: epa:eric Local aliases below The list of local aliases follows bjl blevi ... ... It is important to pay attention to the fact that sendmail does not use the etcaliases file directly. This is an ASCII file used to edit the raw aliases data, but the modified file must first be processed by the newaliases command which is equivalent to the sendmail −bi command to create the dbm aliases files aliases.dir and aliases.pag used by sendmail. In that way, a search through the aliases database is much faster.

20.1.2.3.2 Personal Mail Forwarding Files

In addition to the global e−mail forwarding provided by the etcaliases file, sendmail allows individual users to define their own personal forwarding in the.forward file in their home directories. 467

20.1.2.3.3 Mail Delivery Programs — Mailers

sendmail is the MTA program and it does not handle the mail delivery itself; one exception is when the mail should be delivered over a TCPIP network to another remote host. Instead, sendmail invokes other programs that perform the mail delivery; these programs are known as delivery agents, or simply Mailers. This is illustrated in Figure 20.3. Figure 20.3: Sendmail vs. mailers relations. Mailers definitions are included in the sendmail configuration file. However, the criteria for the selection of a mailer is not a part of the mailers definition; sendmail simply decides when a mailer will be used, and supplies it with the necessary delivery data. On the other side, the mailer s definition supplies sendmail with the information it needs to know how to invoke the mailer. The initial information sendmail needs includes the name and location of the delivery program, but the complete information contains some additional arguments. Generally, the syntax of the sendmail configuration data is quite different from other UNIX configuration data, and we will discuss it in greater detail later. At the moment, let us focus on the mailer s definition specified by the M configuration entry in the sendmail configuration file. Its generic form is: M = m a i l e r − n a m e P = m a i l e r − p a t h F = m a i l e r − f l a g s S = s e n d − r u l e s R = r e c e i v e − r u l e s A=mailer−arguments where: M= Identifies a mailers definition configuration entry with a symbolic name under which sendmail recognizes the corresponding delivery agent. The symbolic name follows the M with no intervening space. P= 468 F= Specifies certain flags that tell sendmail more about the mailer definition. Each flag is a single letter and is Boolean — being set or not set by being correspondingly present or absent. S= Specifies which rule set to use when rewriting the senders address this will be explained later. R= Specifies which rule set to use when rewriting the recipients address this will be explained later. A= Specifies the command−line arguments to be supplied to each corresponding mailer program. There is no limitation regarding the number of specified mailers; names of defined mailers are also arbitrary. However, two mailers are mandatory: the local and prog. These mailers must be always defined, regardless of whether they are needed or used. They enable e−mail delivery to local users mailer local or to local programs mailer prog. If they do not exist, sendmail will not start, and it will print a corresponding error message. Obviously, other mailers should also be defined for sendmail to function properly, but the sendmail program itself does not strictly require them.

20.1.2.3.4 The sendmail Configuration File

This is the central sendmail issue; the configuration file fully defines sendmails behavior — everything is specified within this file. The sendmail configuration file is etcsendmail.cf sometimes usrlibsendmail.cf and lately etcmailsendmail.cf. The sendmail.cf file has three main functions: It defines the sendmail environment. 1. It rewrites addresses into the appropriate syntax for further e−mail processing. 2. It maps addresses into the instructions necessary to deliver the e−mail. 3. Many different configuration entries in the configuration file are required to perform all of these functions: Macro definitions and option entries define the environment. • Rewrite rules transform e−mail addresses from one format to another. • Mailer definitions specify the programs necessary to deliver e−mail. • The syntax of these entries is terse and complex. It makes most system administrators reluctant to even read a sendmail.cf file; only a few feel comfortable with modifying the configuration. At the start time, sendmail reads the configuration file and learns how to behave; for this reason, the syntax is designed to match the program needs, which is not necessarily easy for humans to read. All configuration commands, specifications, options, and variables are similar in that each one is only one character long, and hard to recognize and remember. It is easy to confuse a single character command with a single character variable. Despite that difficulty, the sendmail configuration file must be fully understood for a successful administration.

20.1.2.3.5 The Frozen sendmail Configuration File

sendmail always reads the configuration data when it is started. A converted dbm image of the ASCII configuration file etcsendmail.cf can be created to make this reading faster. This file is called a frozen configuration file etcsendmail.fc or sometimes usrlibsendmail.fc. The following command must be executed to create a frozen configuration file: usrlibsendmail −bz 469 The frozen sendmail configuration is frequently used, but it is not a requirement. sendmail simply checks for the file. If the etcsendmail.fc frozen configuration file exists, it is parsed; otherwise, the etcsendmail.fc configuration file is read.

20.2 Sendmail Configuration