sendmail Command

Purpose

Routes mail for local or network delivery.

Syntax

sendmail [ -ba | -bd | -bD | -bh | -bH | -bi | -bm | -bp | -bs | -bv | -bt [ -Ac File ] [ -C File ] [ -D Log File ] [ -d Value ] ] [ -B Type ] [ -F FullName ] [ -f Name ] [ -G ] [ -h Number ] [ -i ] [ -M x Value ] [ -n ] [ -N Dsn ] [ -OOption=Value ] [ -o OptionValue ] ] [ -p Protocol ] [ -q [ Time ] ] [ -qG name ] [ -qI Substr ] [ -qR Substr ] [ -qS Substr ] [ -R Return ] [ -r  addr ] [ -t ] [ -V Envid ] ] [ -v ] [ -X LogFile ] Address

Note: The Address parameter is optional for -bd, -bi, -bp, -bt, and -qTime ] flags.

Description

Notes:
  • Starting with AIX 7.2, Technology Level 5, the sendmail command uses the sendmail command version 8.18.1. The sendmail command runs by a new smmsp user and smmsp group instead of the root user for enhanced security.
  • In the sendmail command v8.7, and later, the order for name resolution is Domain Name System (DNS), Network Information Services (NIS), Network Interface Services (NIS), and local. To override this default order, specify an order in the /etc/netsvc.conf file or specify the NSORDER environment variable.
  • In AIX® 7.3, the sendmail application supports Simple Authentication and Security Layer (SASL) based authentication.

The sendmail command receives formatted text messages and routes the messages to one or more users. On a network, the sendmail command converts the information format of the message header to match the requirements of the destination system. The sendmail program determines the network of the destination system by using the syntax and content of the addresses.

The sendmail command delivers messages to the following users:
  • Users on the local system.
  • Users connected to the local system by using the TCP/IP protocol.
  • Users connected to the local system by using the Basic Networking Utilities (BNU) command protocol.

Use the sendmail command to deliver only pre-formatted messages and is not a user interface routine. The sendmail command reads standard input for message text and sends a copy of the message to all addresses listed when it reads an end of the message character. The end of the message character is either an end-of-file (Ctrl-D) control sequence or a single period on a line.

sendmail Mail Filter API (Milter)

The sendmail Mail Filter API provides access to mail messages as they are being processed. This allows the third-party programs to filter the meta-information and the content. Filters that are developed by using the sendmail Mail Filter API use threads. It is necessary to alter the per-process limits in your filter. For example, if your filter is frequently used, use the setrlimit subroutine to increase the number of open file descriptors.

Specifying filters in sendmail configs
Use the key letter X (for external) to specify the filters. The following examples are a few of the filters:
  • Xfilter1, S=local:/var/run/f1.sock, F=R
  • Xfilter2, S=inet6:999@localhost, F=T, T=C:10m;S:1s;R:1s;E:5m
  • Xfilter3, S=inet:3333@localhost
You can specify filters in your .mc file. The following filter is attached to a UNIX-domain socket in the /var/run directory:
INPUT_MAIL_FILTER(`filter1', `S=local:/var/run/f1.sock, F=R')
The following filter uses an IPv6 socket on port 999 of the local host:
INPUT_MAIL_FILTER(`filter2', `S=inet6:999@localhost, F=T, T=C:10m;S:1s;R:1s;E:5m')
The following filter uses an IPv4 socket on port 3333 of the local host:
INPUT_MAIL_FILTER(`filter3', `S=inet:3333@localhost')

sendmail mail filter flags

R
Rejects connection if filter is not available.
T
Temporarily fails connection if filter is not available.

If both F=R or F=T is specified, the sendmail command passes the message as if the filter is not present. The separator is a comma (,).

sendmail mail filter timeouts

You can override the default sendmail timeouts with T=x, where x can take the following values:
C
Timeout for connecting to a filter (if 0, use system timeout).
S
Timeout for sending information from the Mail Transmission Agent (MTA) to a filter.
R
Timeout for reading reply from the filter.
E
Overall timeout between sending the end-of-message to the filter and waiting for the final acknowledgment.
The separator between each entry is a semicolon(;).

The default values are T=C:0m;S:10s;R:10s;E:5m.

The InputMailFilters option determines the filters that are started and how the filters are sequenced:
InputMailFilters=filter1, filter2, filter3
This is set automatically according to the order of the INPUT_MAIL_FILTER commands in your .mc file. You can also reset the value by setting confINPUT_MAIL_FILTERS in your .mc file. This option calls the three filters in the order that the filters were specified.

You can define a filter without adding it to the input filter list by using MAIL_FILTER() instead of INPUT_MAIL_FILTER() in your .mc file.

Note: If InputMailFilters is not defined, no filters are used.

Using the sendmail configuration files

In AIX 7.2, Technology Level 3, and earlier, the sendmail command uses a single configuration file, /etc/mail/sendmail.cf to set operational parameters and to determine how the command parses addresses. Starting with AIX 7.2, Technology Level 4, the sendmail command supports the Mail Submission Program mode (MSP_mode) by using the /etc/mail/submit.cf configuration file. The sendmail command in the MSP mode does not require root privileges. Therefore, the sendmail command in MSP mode is more secure as compared to the previous version. The sendmail command uses the sendmail.cf configuration file when the sendmail command runs as mail server daemon in the MTA mode. For more information about the security consideration of the sendmail command, see http://www.sendmail.org/~ca/email/doc8.12/SECURITY.
Note: After the operating system is upgraded to AIX 7.2, Technology Level 5 or later, the /etc/mail directory contains the new /etc/mail/sendmail.cf and /etc/mail/submit.cf files. The existing /etc/mail/sendmail.cf and /etc/mail/submit.cf files from the earlier versions of AIX are copied to the /lpp/save.config/etc/mail directory.
The sendmail configuration files are as described:
/etc/mail/sendmail.cf
This configuration file is used when the sendmail command runs as mail server daemon in the MTA mode. By default, the sendmail.cf file uses the mail queue in the /var/spool/mqueue directory. On system boot, the sendmail MTA daemon is started in the /etc/rc.tcpip directory by default. To manually start the sendmail MTA daemon, enter the following command:
# startsrc -s sendmail -a " -bd -q30m"
/etc/mail/submit.cf
This configuration file is used by the sendmail command to operate in the MSP mode. By default, the submit.cf file uses the system mail queue in the /var/spool/clientmqueue directory. The sendmail command operates in the MSP mode under the following scenarios:
  • When the sendmail command is run at command line or is called by another mail facility (such as the mail command) to send email.
  • When the sendmail command is started as client-queue runner. The sendmail client-queue runner identifies the undelivered messages in the /var/spool/clientmqueue directory and submits the messages to the sendmail MTA daemon for delivery. To run the sendmail command as a queue runner in MSP mode manually, enter the following command:
    # /usr/lib/sendmail -Ac -q 30m 

You can also set the sendmail MTA daemon to start automatically whenever the system boots by editing the /etc/rc.tcpip file. For instructions about editing the /etc/rc.tcpip file, see Starting the sendmail daemon during system boot.

Restarting and refreshing the sendmail processes

The configuration files that are used by the sendmail command are text files that you can edit by using any text editor. After you modify any of these configuration files, you must restart or refresh the MTA daemon and the MSP for the changes to take effect.

The current process ID of the sendmail command is stored in the /etc/mail/sendmail.pid file. To allow the sendmail command reread the newly edited configuration files, enter the following kill command:

#kill -15 `head -1 /etc/mail/sendmail.pid`

If the srcmstr command is running, you can run the refresh command to build the configuration database, the aliases database, and the NLS database again:

#refresh -s sendmail

If you started the sendmail MSP manually, and if the srcmstr command does not control the sendmail process, you can stop the sendmail process by using the following kill command:

# kill <pid of the sendmail: Queue runner >

Migrating to AIX 7.2, Technology Level 4

If you are running AIX 7.2, Technology Level 3, or earlier, and if you configure the sendmail command, when you migrate to AIX 7.2, Technology Level 4, the sendmail command runs as an MTA daemon. Enter the following command to back up the sendmail.cf configuration file before you start the migration operation:

# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old

After the migration operation is complete, the previous sendmail.cf configuration file is transferred to the new sendmail.cf configuration file.

Complete the following steps after you migrate your AIX operating system to AIX 7.2, Technology Level 4, or later:
  1. To restore the sendmail.cf backup file when you cannot find the sendmail.cf file after migration, enter the following command:
    # cp /etc/mail/sendmail.cf.old /etc/mail/sendmail.cf
  2. To restart and refresh the sendmail processes, enter the following commands:
    # startsrc -s sendmail -a " -bd -q30m"
    # refresh -s sendmail

    These commands run the sendmail command as MTA.

The sendmail command rereads the databases and continues the operation with the sendmail.cf configuration file.

Defining Aliases

The sendmail command allows you to define aliases to use when the sendmail command handles the local mail. Aliases are alternative names that you can use in place of elaborate network addresses or to build distribution lists.

Define aliases in the /etc/mail/aliases file. This file is a text file that you can edit. The sendmail command uses a database version of this file. Before any changes made to the /etc/mail/aliases file become effective, you must build a new alias database by using the sendmail -bi command or the newaliases command.

Berkeley database (DB) support is available on AIX for Sendmail 8.11.0. The sendmail command continues to read the aliases in the Database Manager (DBM) format until the aliases database gets rebuilt. Once rebuilt, sendmail command reads the aliases in the Berkeley DB format and store them in the /etc/mail/aliases.db file.

Note: When you define aliases in the /etc/mail/aliases file, use only lowercase characters for nested aliases. Uppercase characters on the right side of an alias are converted to lowercase before you save in the aliases database. In the following example, mail that is sent to testalias fails as TEST is converted to test when the second line is stored.
TEST: user@machine
testalias: TEST

Every system must have a user or user alias that is designated as the alias. The default postmaster alias is a root file. You can assign this alias to a different user in the /etc/mail/aliases file. The postmaster alias allows other users outside your system to send mail to a known ID and to get information about mailing to users on your system. Also, users on your system can send problem notifications to the postmaster ID.

The sendmail command first opens a database in the format of hash-style aliases file. If it fails or if the NEWDB support is not compiled, the command opens a new Database Manager (NDBM) database. If that fails, the sendmail command reads the aliases source file into its internal symbol table.

Flags

Table 1. Flags
Item Description
-Ac File Specifies the sendmail command to choose an alternative configuration file based on the operative mode. If you specify -bm, -bs, or -t flags, the sendmail command uses the submit.cf configuration file. If any other flags are specified, and for compatibility with earlier versions, the sendmail command uses the sendmail.cf configuration file. If you do not specify the File variable, by default, the sendmail command uses the submit.cf configuration file.
-B Type Sets the body type to Type. Current legal values are 7BI or 8BITMIME.
Note: The -b flag is mutually exclusive.
-ba Starts the sendmail command in ARPANET mode. All input lines to the command must end with a carriage return and a line feed (CR-LF). The sendmail command generates messages with a CR-LF at the end and looks at the From: and Sender: fields to find the name of the sender. Starting with the sendmail command version 8.18.1, the behavior is updated to expect a standard end-of-data sequence (<CR><LF>.<CR><LF>) instead of a nonstandard sequence (<LF>.<CR><LF>) and ß(<LF>.<LF>).
-bd Starts the sendmail command as a daemon that runs in the background as a Simple Mail Transfer Protocol (SMTP) mail router.
-bD Starts the sendmail command as a daemon that runs in the foreground as an SMTP mail router.
-bh Prints the persistent host status database.
-bH Purges the persistent host status database.
-bi Builds the alias database from information that is defined in the /etc/mail/aliases file. Running the sendmail command with this flag is the same as running the newaliases command.
-bm Delivers mail in the usual way by default.
-bp Prints a listing of the mail queue. Running the sendmail command with this flag is the same as running the mailq command.
-bs Uses the SMTP as described in RFC821 to collect mail from the standard input. This flag includes the operations of the -ba flag that are compatible with SMTP.
-bt Starts the sendmail command in address test mode. Using this mode you can enter interactive addresses and watch as the sendmail command displays the steps it takes to parse the address. At the test-mode prompt, enter a rule set or multiple rule sets separated by commas and an address. Use this mode for debugging the address parsing rules in a new configuration file.
-bv Starts the sendmail command with a request to verify the user IDs provided in the Address parameter field of the command. The sendmail command responds with a message that informs which IDs can be resolved to a mailer command. It does not try to collect or deliver a message. Use this mode to validate the format of user IDs, aliases, or mailing lists.
-C File Starts the sendmail command by using an alternative configuration file that the File variable specifies. Use the -C flag together with the -bt flag to test a new configuration file before you install it as the configuration file that runs.
-D Log File Sends the debugging output to the specified log file. The -D option must be before the -d option.
-d Value Sets the debugging value to the value specified by the Value variable. The only valid value is 21.n, where n is any nonzero integer. This produces information about address parsing and is used with the -bt flag. Higher values of n produce more verbose information. Root permissions are required for this flag.
-F FullName Sets the full name of the sender to the string provided in the FullName variable.
-f Name Sets the name of the from person (the envelope sender of the mail). This address might also be used in the From: header if that header is missing during initial submission. The envelope sender address is used as the recipient for delivery status notifications and might also appear in a Return-path: header. The -f flag must be used only by trusted users (normally root, daemon, and uucp) or if the person you are trying to become is the same as the person you are. Otherwise, a X-Authentication-Warning header is added to the message.
-G Relay (gateway) submission of a message. For example, when the rmail command calls the sendmail command.
-h Number Sets the hop count to the value that the Number variable specifies. The hop count is the number of times that the SMTP router (not just the local copy of the sendmail command) processes the message. The mail router increments the hop count every time that the message is processed. When it reaches a limit, the message is returned with an error message to prevent infinite loops in the mail system.
-i Ignores dots alone on lines by themselves in incoming messages. This option must be set if you are reading data from a file.
-L Sets the identifier that is used in syslog messages to the supplied tag.
-M x Value Sets marco x to the specified Value.
-N Dsn Sets the notification conditions of the delivery status to Data Source Name (DSN). The following conditions are the notification conditions of the delivery status:
never
For no notifications or for a comma-separated list of the values.
failure
For notification if delivery failed.
delay
For notification if delivery is delayed.
success
For notification when the message is successfully delivered.
-n Prevents the sendmail command from interpreting aliases.
-O Option=Value Sets the Option to the specified Value. Use for long-form option names.
-o Option [ Value ] Sets the Option variable. If the option is a valued option, you must specify a value for the Value variable.
Note: For valid values, see Options for the sendmail Command in the sendmail.cf file in Performance Tools Guide and Reference.
-p Protocol Sets the sending protocol. You must set this option. You can set Protocol in the form Protocol:Host to set both the sending protocol and the sending host. For example, -pUUCP:uunet sets the sending protocol to UUCP and the sending host to uunet. Some existing programs use -oM flag to set the r and s macros, which is equivalent to the -p flag.
-qI Substr Limits process jobs to those containing Substr as a substring of the queue ID.
-qG name Processes jobs in a queue group are called by name only.
-qR Substr Limits process jobs to those containing Substr as a substring of one of the recipients.
-qS Substr Limits process jobs to those containing Substr as a substring of the sender.
-qTime ] Processes saved messages in the queue at the intervals that the Time variable specifies. If you do not specify the Time variable, the -q flag processes the queue at once.
-R Return Sets the amount of the message to be returned if the message bounces. The Return parameter can be full to return the entire message or hdrs to return only the headers.
-r addr An obsolete form of -f.
-t Sends the message to the recipients specified in the To:, Cc:, and Bcc: fields of the message header and to the users specified on the command line.
-V Envid Sets the original envelope ID. This is propagated across SMTP to servers that support DSNs and is returned in DSN-compliant error messages.
-v Starts the sendmail command in the verbose mode. The sendmail command displays the messages about the status of transmission and the expansion of aliases.
-X LogFile Logs all traffic in and out of the sendmail command in a LogFile for debugging mailer problems. Use this flag sparingly as it produces a lot of data rapidly.

You can also set or remove the sendmail configuration processing options and is used by the user responsible for the mail system. To set these options, use the -o flag on the command line or the O control line in the /etc/mail/sendmail.cf configuration file.

Exit Status

The sendmail command returns exit status values. These exit values are defined in the /usr/include/sysexits.h file. The following table summarizes the meanings of these return values:

Table 2. Exit Values
Item Description
EX_CANTCREAT The sendmail command cannot create a file that the user specified.
EX_CONFIG An error is found in the format of the configuration file.
EX_DATAERR The input data is incorrect.
EX_IOERR An error occurred during I/O.
EX_NOHOST The sendmail command does not recognize the specified hostname.
EX_NOINPUT An input file (not a system file) did not exist or is not readable.
EX_NOPERM The user does not have permission to perform the requested operation.
EX_NOUSER The sendmail command does not recognize a specified user ID.
EX_OK The sendmail command successfully completed.
EX_OSERR A temporary operating system error occurred. An example of such an error is a failure to create a new process.
EX_OSFILE A system file error occurred. For example, a system file such as /etc/passwd does not exist, cannot be opened, or has another type of error that prevents it from being used.
EX_PROTOCOL The remote system returns something that is incorrect during a protocol exchange.
EX_SOFTWARE An internal software error occurred (including bad arguments).
EX_TEMPFAIL The sendmail command cannot create a connection to a remote system. Try the request again later.
EX_UNAVAILABLE A required service or resource by the sendmail command is not available.
EX_USAGE The command syntax is not correct.

Security

Attention RBAC users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations that are associated with this command, see the lssecattr command or the getcmdattr subcommand.

Auditing Events

Table 3. Auditing Events
Event Information
SENDMAIL_Config Configuration event
SENDMAIL_ToFile File-creation event

Example

To display the sendmail version, enter the following command:

echo \$Z | sendmail -d0

A message similar to the following message is displayed:

Version AIX5.2/8.11.6p2
 Compiled with: LDAPMAP MAP_REGEX LOG MATCHGECOS MIME7TO8 MIME8TO7
             NAMED_BIND NDBM NETINET NETINET6 NETUNIX NEWDB NIS NISPLUS
                QUEUE SCANF SMTP USERDB XDEBUG

============ SYSTEM IDENTITY (after readcf) ============
      (short domain name) $w = dodgers
  (canonical domain name) $j = dodgers.usca.ibm.com
         (subdomain name) $m = usca.ibm.com
              (node name) $k = dodgers
========================================================

Recipient names must be specified
# oslevel -r
5200-02
#

Files

Table 4. Files
Item Description
/usr/sbin/sendmail The directory contains the sendmail command.
/usr/sbinmailq/ The directory contains the mail queue.
/usr/sbin/newaliases The directory contains the alias database.
/usr/sbin/mailstats The directory contains the statistics that are found in the /usr/lib/sendmail.st file.
/etc/mail/aliases The directory contains the text version of the sendmail command aliases.
/etc/mail/aliases.db The directory contains a Berkeley DB formatted database for aliases.
/etc/mail/aliases.dir The directory contains a DBM-formatted database for aliases.
/etc/mail/aliases.pag The directory contains a DBM-formatted database for aliases.
/etc/mail/sendmail.cf The directory contains the text version of the sendmail configuration file.
/etc/mail/submit.cf The directory contains the text version of the sendmail configuration file. If this file exists, this file is considered as the default configuration file.
/etc/sendmail.st The directory contains mail routing statistics information.
/usr/lib/smdemon.cleanu The directory maintains aging copies of the log file that is found in the /var/spool/mqueue directory.
/var/spool/mqueue The directory contains the temporary files and the log file that is associated with the messages in the mail queue.
/usr/bin/uux The directory contains the mailer command to deliver Basic Networking Utilities (BNU) mail.
/usr/bin/bellmail The directory contains the mailer command to deliver local mail.