home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Previous Section Next Section

A=

The argv for this delivery agent All versions

The program that is to be run (specified by the P= delivery agent equate) is given its C-language char **argv array (list of command-line arguments) by this A= delivery agent equate. This delivery agent equate is traditionally the last one specified because prior to V8.7, the argv arguments were all those from the = to the end of the line:

Mlocal, P=/bin/mail, F=rlsDFMmnP, S=10, R=20, A=mail -d $u
                                                 
                                                prior to V8.7, argv to end of line ...

Beginning with V8.7, the A= is treated like any other delivery agent equate, in that it ends at the end of line or at the first comma. The backslash character can be used as a prefix to embed commas in the A= delivery agent equate.

Macros are expanded and can be used in this argv array. For example:

A=mail -d $u

The A= begins the declaration of the argument array. The program that is specified by the P= delivery agent equate (/bin/mail) will be executed with an argv of:

argv[0] = "mail"
argv[1] = "-d"           switch means perform final delivery
argv[2] = "fred"         where sendmail macro $u contains fred 

The macro value of $u contains the current recipient name or names ($u). Another sendmail macro that commonly appears in A= fields is $h, the recipient host ($h). You are, of course, free to use any sendmail macro you find necessary as a part of this argv array. Note that $u is special, in that if it is missing, sendmail will speak SMTP to the delivery agent (See this section), or LMTP if the delivery agent has the F=z flag set (F=z). Also note that any arguments in excess of the maximum number defined by MAXPV (MAX...), usually 40, are silently ignored.

How to define A= with your mc configuration

Under V8 sendmail's mc configuration you can define the A= delivery agent equate using one of the handy mc macros provided. With the local delivery agent, for example, you can change the A= equate like this:

define(`LOCAL_MAILER_ARGS', `put.local -l -d $u')

See the section describing a particular delivery agent to find an appropriate mc macro with which to redefine the A= for that delivery agent. See Table 20-1, in Section 20.4, for a guide to all delivery agents. And note that when $u appears in an A= equate, it should always be last because there might be multiple recipients.

In general, the definitions in the cf/ostype subdirectory are pretuned in a way that is best for most sites. If you want to make changes, remember that each definition that you put in your mc file replaces the definition in cf/ostype. Therefore, it's best to copy an existing definition and modify it for your own use. Just be sure you don't omit something important.

The use of $h in A=TCP

For network delivery via the P=[IPC] delivery agent, the A= delivery agent equate is usually declared like this:

A=TCP $h

The value in $h is the value returned by the parse rule set 0's $@ operator and is usually the name of the host to which sendmail should connect. During delivery the sendmail program expands this hostname into a possible list of MX records.[9] It attempts delivery to each MX record. If all delivery attempts fail and if the V8 FallbackMXhost option (FallbackMXhost) is set, delivery is attempted to that fallback host. In all cases, if there are no MX records, delivery is attempted to the A or AAAA record instead.

[9] Unless (V8.8 and above) the F=0 delivery agent flag is set (F=0 (zero)), or unless the hostname is surrounded by square brackets.

Beginning with V8 sendmail, $h (possibly as returned by the parse rule set 0) can be a colon-separated list of hosts. The sendmail program attempts to connect to each in turn, left to right:

A=TCP hostA:hostB:hostC   

Here, it tries to connect to hostA first. If that fails, it next tries hostB, and so on. As usual, trying a host means trying its MX records first, or its A or AAAA record if there are no MX records.

The host (as $h) is usually the only argument given to TCP. But, strictly speaking, TCP can accept two arguments, like this:

A=TCP hostlist  port  

The port is usually omitted and so defaults to 25. However, a port number can be included to force sendmail to connect on a different port.

To illustrate, consider the need to force mail to a gateway machine that must always be delivered on a particular port. First, design a new delivery agent that uses TCP for transport:

Mgateway, P=[IPC], ..., A=TCP gateway.domain $h

Here, any mail that selects the gateway delivery agent is transported over the network (the TCP) to the machine gateway.domain. The port number is carried in $h, which usually carries the hostname.

Next, design a rule in the parse rule set 0 that selects this delivery agent:

R$+ < @ $+ .gateway > $*            $#gateway $@ 26 $: $1 < @ $2 .gateway> $3

This rule selects the gateway delivery agent for any address that ends in .gateway. The host part that is returned by the $@ is the port number to use. The $: part (the address) is passed in the envelope. Note that the gateway also has to be listening on the same port for this to work.

In the event that you wish to carry the port number in a sendmail macro, you can do so by specifying the host with $h. For example:

Mgateway, P=[IPC], ..., A=TCP $h $P
R$+ < @ $+ .gateway > $*            $#gateway $@ $2 $: $1 < @ $2 .gateway> $3

Then sendmail can be run with the command-line argument:

-MP26

to cause gateway mail to go out on port 26.

The special case of $u in A=

The $u sendmail macro is special in the A= delivery agent equate's field. If $u does not appear in the array, sendmail assumes the program in the P= delivery agent equate speaks SMTP, or LMTP if the delivery agent has the F=z flag set (F=z). If $u does appear in the array, sendmail assumes that the program in P= will speak neither SMTP nor LMTP. Consequently, you should never use a $u when defining mail delivery agents that speak SMTP or LMTP. All agents that use [IPC] in their P= delivery agent equate's field must use SMTP.

If $u appears and the F=m delivery agent flag is also specified, the argument containing $u is repeated as many times as there are recipients. For example, a typical uucp delivery agent definition looks like this:

Muucp, P=/bin/uux, F=m sDFMhuU, S=13, R=23, A=uux - -r $h!rmail ($u)  
                                                               
                      note                                      note 

In this example, the m delivery agent flag is set in the F= delivery agent equate's field, which tells sendmail that this delivery agent can deliver to multiple recipients simultaneously. The $u sendmail macro is also included as one of the arguments specified by the A= command-line array. Thus, if mail is sent with this delivery agent to multiple recipients—say, jim, bill, and joe—the ($u) argument[10] is repeated three times, once for each recipient:

[10] When $u is used as part of a UUCP delivery agent's A= array, it should be parenthesized. This is what the uux(1) program expects.

uux - -r $h!rmail (jim) (bill) (joe)

Deliver to a Unix domain socket

Beginning with V8.10 sendmail, delivery can be made to Unix domain sockets. This is enabled by defining a delivery agent that has P= defined as [IPC] and A= defined with FILE, followed by the full pathname of the Unix domain socket.

To illustrate, consider a site that has devised a daemon which will deliver local mail into a central database. Such a daemon might be best designed to listen for inbound email on a Unix domain socket, and to receive that mail with the LMTP protocol. Should such a daemon exist, you could tie sendmail into it with a simple setup such as this:

define(`confLOCAL_MAILER', `dbd')
MAILER_DEFINITIONS
Mdbd, P=[IPC], F=lsDFMmnqSXzA5@/:|,
               S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
               T=DNS/RFC822/SMTP, A=FILE /var/run/dbd

Here, in our mc configuration file, we declare that the dbd delivery agent will become our preference for all local delivery by defining the confLOCAL_MAILER mc configuration macro (Section 20.3.1.3).

Then, under MAILER_DEFINITIONS, we define the new dbd delivery agent. Its P= is defined as [IPC], which tells sendmail that delivery will be over a socket connection. The FILE following the A= tells sendmail that the socket will be a Unix domain socket. The /var/run/dbd path is the full pathname of the Unix domain socket. If the socket does not exist, delivery will fail.[11]

[11] It is the responsibility of the listening program to make certain the socket exists. In an rc file, you should launch the listening program before you launch sendmail.

The F=l delivery agent flag (F=l (lowercase L)) tells sendmail that this delivery agent handles final, local delivery. The F=z delivery agent flag (F=z) tells sendmail to deliver using the LMTP protocol.

    Previous Section Next Section