Mail Administration Guide

Special Macros, Conditionals

Special macros are referenced with the construct $x, where x is the name of the macro to be matched (LHS) or inserted (RHS). Lowercase letters are reserved for special semantics, and some special characters are reserved to provide conditionals.

The macros shown in Table 3-9 must be defined to transmit information into sendmail.

Table 3-9 Required sendmail Macros

Macro 

Description 

$a

Origination date in ARPANET format 

$b

Current date in ARPANET format 

$c

Hop count 

$d

Date in UNIX (ctime()) format

$e

Printed out when SMTP starts 

$f

Sender from name 

$g

Sender name relative to the recipient 

$h

Recipient host 

$i

Queue ID 

$j

The official domain name for this site; should be the first word of the $e macro; $j should be in domain name format

$k

The UUCP node name (from uname)

$l

The format of the UNIX From line

$m

The domain part of the gethostname return value

$n

The name of the daemon (for error messages) 

$o

List of characters that are considered tokens 

$p

sendmail's process ID

$q

Default format of the sender address. Specifies how a sender should appear in a message when it is created. 

$r

Protocol used 

$s

Sender's host name 

$t

Numeric representation of the current time 

$u

Recipient user 

$v

Version number of sendmail

$w

Host name of this site 

$x

Full name of the sender 

$z

Home directory of the recipient 

$-

Sender address 


Note -

In the SunOS 4.x releases, $w is the fully qualified hostname. In the Solaris 2.6 release, $w is the short version of the hostname.


For example:


De$j Sendmail $v ready at $b
DnMAILER-DAEMON
DlFrom $g $d
Do.:%@!^=/
Dq$g$?x ($x)$.
Dj$H.$D

You should not need to change any of these macros except under unusual circumstances. For example, you might want to change the first line, which defines the banner for security. You might want to change the last two lines to make several hosts look like one host.

An acceptable alternative for the $q macro is:


$?x$x $.<$g>

This entry corresponds to the following two formats:


doe@acme.com (John Doe)
John Doe <doe@acme.com>

Some macros are defined by sendmail for use in mailer arguments or for other contexts.Table 3-10 shows these macros.

Table 3-10 Additional sendmail Macro Definitions

Macro 

Description 

$m

Domain name 

$p

sendmail process ID

You can use three types of dates. The $a and $b macros are in ARPANET format; $a is the time as extracted from the Date: line of the message (if there was one), and $b is the current date and time (used for postmarks). If no Date: line is found in the incoming message, $a is also set to the current time. The $d macro is equivalent to the $a macro in UNIX (ctime) format.

The $f macro is the ID of the sender as originally determined; for a message mailed to a specific host, the $g macro is set to the name of the sender relative to the recipient. For example, suppose the sender eric sends a message to bollard@matisse from the machine ucbarpa. The value of $f will be eric and the value of $g will be eric@ucbarpa.

The $x macro is set to the full name of the sender, which can be determined in several ways. It can be passed as a flag to sendmail (from the value of the Full-name: line in the header or use the comment field of a From: line). If the name can't be determined from the Full-name: or From: lines, and if the message is being originated locally, the full name is looked up in the /etc/passwd file. It can also be read from the name environment variable.

When a message is sent, the $h, $u, and $z macros are set to the host, user, and home directory (if local) of the recipient. The first two macros are set from the $@ and $: part of the rewriting rules respectively.

The $p and $t macros are used to create unique strings (for example, for the Message-Id: field). The $i macro is set to the queue ID on this host; if put into the time stamp line, it can be useful for tracking messages. The $v macro is set to be the version number of sendmail; this is normally put in time stamps and is extremely useful for debugging. It can, however, be a security risk if a publicized bug with the current version can be exploited. The $w macro is set to the primary name of this host, as given by gethostname() and gethostbyname(). The $c field is set to the "hop count"; that is, the number of times this message has been processed, which can be determined by counting the time stamps in the message.

The $r and $s fields are set to the protocol used to communicate with sendmail and the sending host name.

You can specify conditionals by using the syntax:


$?x text1 $| text2 $

This example inserts text1 if the macro $x is set, and text2 otherwise. The else (c $|) clause can be omitted.