Linux sendmail command
sendmail is a general purpose email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet.
sendmail sends a message to one or more recipients, routing the message over whatever networks are necessary. sendmail does internetwork forwarding as necessary to deliver the message to the correct place.
sendmail is not intended as a user interface routine; other programs provide user-friendly front ends. sendmail is used only to deliver pre-formatted messages.
With no flags specified, sendmail reads its standard input up to an end-of-file or a line consisting only of a single dot, and sends a copy of the message found there to all of the addresses listed. It determines the network(s) to use based on the syntax and contents of the addresses.
Local addresses are looked up in a file and aliased appropriately. Aliasing can be prevented by preceding the address with a backslash. Beginning with version 8.10, the sender is included in any alias expansions; for example, if "john" sends mail to "group", and "group" includes "john" in the expansion, then the letter will also be delivered to "john".
sendmail [flags] [address ...]
sendmail can also be invoked, with special functionality, using the following commands.
See below for more information.
|-Ac||Use submit.cf even if the operation mode does not indicate an initial mail submission.|
|-Am||Use sendmail.cf even if the operation mode indicates an initial mail submission.|
|-Btype||Set the body type to type. Current legal values are 7BIT or 8BITMIME.|
|-ba||Go into ARPANET mode. All input lines must end with a CR-LF, and all messages will be generated with a CR-LF at the end. Also, the "From:" and "Sender:" fields are examined for the name of the sender.|
|-bd||Run as a daemon. sendmail will fork and run in background listening on socket 25 for incoming SMTP connections. This is normally run from /etc/rc.|
|-bD||Same as -bd, except it runs in foreground.|
|-bh||Print the persistent host status database.|
|-bH||Purge expired entries from the persistent host status database.|
|-bi||Initialize the alias database.|
|-bm||Deliver mail in the usual way (This is the default).|
|-bp||Print a listing of the queue(s).|
|-bP||Print number of entries in the queue(s); only available with shared memory support.|
|-bs||Use the SMTP protocol as described in RFC 821 on standard input and output. This flag implies all the operations of the -ba flag that are compatible with SMTP.|
|-bt||Run in address test mode. This mode reads addresses and shows the steps in parsing; it is used for debugging configuration tables.|
|-bv||Verify names only; do not try to collect or deliver a message. Verify mode is normally used for validating users or mailing lists.|
|-Cfile||Use alternate configuration file. sendmail gives up any enhanced (set-user-ID or set-group-ID) privileges if an alternate configuration file is specified.|
|-D logfile||Send debugging output to the indicated log file instead of stdout.|
|-dcategory.level...||Set the debugging flag for category to level. The category is either an integer or a name specifying the topic, and level an integer specifying the level of debugging output desired. Higher levels generally mean more output. More than one flag can be specified by separating them with commas. A list of numeric debugging categories can be found in the TRACEFLAGS file in the sendmail source distribution. The option -d0.1 prints the version of sendmail and the options used during the compile. Most other categories are only useful with, and documented in, sendmail's source code.|
|-Ffullname||Set the full name of the sender.|
|-fname||Sets the name of the "from" person (i.e., the envelope sender of the mail). This address may 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 may also appear in a "Return-Path:" header. -f should only be used by "trusted" users (normally root, daemon, and network) or if the person you are trying to become is the same as the person you are. Otherwise, an "X-Authentication-Warning" header will be added to the message.|
|-G||Relay (gateway) submission of a message, e.g., when rmail calls sendmail.|
|-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, most likely the victim of an aliasing loop. If not specified, "Received:" lines in the message are counted.|
|-i||Ignore dots alone on lines by themselves in incoming messages. This should be set if you are reading data from a file.|
|-L tag||Set the identifier used in syslog messages to the supplied tag.|
|-N dsn||Set delivery status notification conditions to dsn, which can be "never" for no notifications, or a comma separated list of the values "failure" to be notified if delivery failed, "delay" to be notified if delivery is delayed, and "success" to be notified when the message is successfully delivered.|
|-n||Don't do aliasing.|
|-O option=value||Set option option to the specified value. This form uses long names. See below for more details.|
|-ox value||Set option x to the specified value. This form uses single character names only.|
|-pprotocol||Set the name of the protocol used to receive the message. This can be a simple protocol name such as "UUCP" or a protocol and hostname, such as "UUCP:ucbvax".|
|-q[time]||Process saved messages in the queue at given intervals. If time is omitted, process the queue once. The time is given as a tagged number, with "s" being seconds, "m" being minutes (default), "h" being hours, "d" being days, and "w" being weeks. For example, "-q1h30m" or "-q90m" would both set the timeout to one hour thirty minutes. By default, sendmail will run in the background. This option can be used safely with -bd.|
|-qp[time]||Similar to -qtime, except that instead of periodically forking a child to process the queue, sendmail forks a single persistent child for each queue that alternates between processing the queue and sleeping. The sleep time is given as the argument; it defaults to 1 second. The process will always sleep at least 5 seconds if the queue was empty in the previous queue run.|
|-qf||Process saved messages in the queue once and do not fork, but run in the foreground.|
|-qGname||Process jobs in queue group called name only.|
|-q[!]Isubstr||Limit processed jobs to those containing substr as a substring of the queue id or not when ! is specified.|
|-q[!]Qsubstr||Limit processed jobs to quarantined jobs containing substr as a substring of the quarantine reason or not when ! is specified.|
|-q[!]Rsubstr||Limit processed jobs to those containing substr as a substring of one of the recipients or not when ! is specified.|
|-q[!]Ssubstr||Limit processed jobs to those containing substr as a substring of the sender or not when ! is specified.|
|-Q[reason]||Quarantine a normal queue items with the given reason or unquarantine quarantined queue items if no reason is given. This should only be used with some sort of item matching using as described above.|
|-R return||Set 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. In the latter case also local bounces return only the headers.|
|-rname||An alternate and obsolete form of the -f flag.|
|-t||Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission.|
|-V envid||Set the original envelope id. This is propagated across SMTP to servers that support DSNs and is returned in DSN-compliant error messages.|
|-v||Go into verbose mode. Alias expansions will be announced, etc.|
|-X logfile||Log all traffic in and out of mailers in the indicated log file. This should only be used as a last resort for debugging mailer bugs. It will log a lot of data very quickly.|
|--||Stop processing command flags and use the rest of the arguments as addresses.|
There are also a number of processing options that may be set. Normally these will only be used by a system administrator. Options may be set either on the command line using the -o flag (for short names), the -O flag (for long names), or in the configuration file. This is a partial list limited to those options that are likely to be useful on the command line and only shows the long names. The options are:
|AliasFile=file||Use alternate alias file.|
|HoldExpensive||On mailers that are considered "expensive" to connect to, don't initiate immediate connection. This requires queueing.|
|CheckpointInterval=N||Checkpoint the queue file after every N successful deliveries (default 10). This avoids excessive duplicate deliveries when sending to long mailing lists interrupted by system crashes.|
|DeliveryMode=x||Set the delivery mode to x. Delivery modes are "i" for interactive (synchronous) delivery, "b" for background (asynchronous) delivery, "q" for queue only; i.e., actual delivery is done the next time the queue is run, and "d" for deferred: the same as "q" except that database lookups for maps which have set the -D option (default for the host map) are avoided.|
|ErrorMode=x||Set error processing to mode x. Valid modes are "m" to mail back the error message, "w" to "write" back the error message (or mail it back if the sender is not logged in), "p" to print the errors on the terminal (default), "q" to throw away error messages (only exit status is returned), and "e" to do special processing for BerkNet. If the text of the message is not mailed back by modes "m" or "w" and if the sender is local to this machine, a copy of the message is appended to the file dead.letter in the sender's home directory.|
|SaveFromLine||Save UNIX-style From lines at the front of messages.|
|MaxHopCount=N||The maximum number of times a message is allowed to "hop" before we decide it is in a loop.|
|IgnoreDots||Do not take dots on a line by themselves as a message terminator.|
|SendMimeErrors||Send error messages in MIME format. If not set, the DSN (Delivery Status Notification) SMTP extension is disabled.|
|ConnectionCacheTimeout=timeout||Set connection cache timeout.|
|ConnectionCacheSize=N||Set connection cache size.|
|LogLevel=n||The log level.|
|MeToo=False||Don't send to "me" (the sender) if I am in an alias expansion.|
|CheckAliases||Validate the right hand side of aliases during a newaliases command.|
|OldStyleHeaders||If set, this message may have old style headers. If not set, this message is guaranteed to have new style headers (i.e., commas instead of spaces between addresses). If set, an adaptive algorithm is used that will correctly determine the header format in most cases.|
|QueueDirectory=queuedir||Select the directory in which to queue messages.|
|StatusFile=file||Save statistics in the named file.|
|Timeout.queuereturn=time||Set the timeout on undelivered messages in the queue to the specified time. After delivery has failed (e.g., because of a host being down) for this amount of time, failed messages will be returned to the sender. The default is five days.|
|UserDatabaseSpec=userdatabase||If set, a user database is consulted to get forwarding information. You can consider this an adjunct to the aliasing mechanism, except that the database is intended to be distributed; aliases are local to a particular host. This may not be available if your sendmail does not have the USERDB option compiled in.|
|ForkEachJob||Fork each job during queue runs. May be convenient on memory-poor machines.|
|SevenBitInput||Strip incoming messages to seven bits.|
|EightBitMode=mode||Set the handling of eight bit input to seven bit destinations to mode: m (mimefy) will convert to seven-bit MIME format, p (pass) will pass it as eight bits (but violates protocols), and s (strict) will bounce the message.|
|MinQueueAge=timeout||Sets how long a job must ferment in the queue between attempts to send it.|
|DefaultCharSet=charset||Sets the default character set used to label 8-bit data that is not otherwise labelled.|
|DialDelay=sleeptime||If opening a connection fails, sleep for sleeptime seconds and try again. Useful on dial-on-demand sites.|
|NoRecipientAction=action||Set the behaviour when there are no recipient headers (To:, Cc: or Bcc:) in the message to action: none leaves the message unchanged, add-to adds a To: header with the envelope recipients, add-apparently-to adds an Apparently-To: header with the envelope recipients, add-bcc adds an empty Bcc: header, and add-to-undisclosed adds a header reading `To: undisclosed-recipients:;'.|
|MaxDaemonChildren=N||Sets the maximum number of children that an incoming SMTP daemon will allow to spawn at any time to N.|
|ConnectionRateThrottle=N||Sets the maximum number of connections per second to the SMTP port to N.|
In aliases, the first character of a name may be a vertical bar ("|") to cause interpretation of the rest of the name as a command to pipe the mail to. It may be necessary to quote the name to keep sendmail from suppressing the blanks from between arguments. For example, a common alias is:
msgs: "|/usr/bin/msgs -s"
Aliases may also have the syntax ":include:filename" to ask sendmail to read the named file for a list of recipients. For example, an alias such as:
would read /usr/local/lib/poets.list for the list of addresses making up the group.
Sendmail returns an exit status describing what it did. The exit codes are listed below, and defined in <sysexits.h>.
|EX_OK||Successful completion on all addresses.|
|EX_NOUSER||Username not recognized.|
|EX_UNAVAILABLE||Catchall meaning necessary resources were not available.|
|EX_SYNTAX||Syntax error in address.|
|EX_SOFTWARE||Internal software error, including bad arguments.|
|EX_OSERR||Temporary operating system error, such as "cannot fork".|
|EX_NOHOST||Host name not recognized.|
|EX_TEMPFAIL||Message could not be sent immediately, but was queued.|
If invoked as newaliases, sendmail will rebuild the alias database.
If invoked as mailq, sendmail will print the contents of the mail queue.
If invoked as hoststat, sendmail will print the persistent host status database.
If invoked as purgestat, sendmail will purge expired entries from the persistent host status database.
If invoked as smtpd, sendmail will act as a daemon, as if the -bd option were specified.
Except for the file /etc/mail/sendmail.cf itself, the following pathnames are all specified in /etc/mail/sendmail.cf. Thus, these values should only be considered approximations.
|/etc/mail/aliases||raw data for alias names|
|/etc/mail/aliases.db||database of alias names|
sendmail [email protected]
sendmail will read your email from standard input, and attempt to send the email when you enter a single dot (".") on a new line and press enter. As an example, after running the above command, you could type:
From: [email protected] To: [email protected] Hi, this is my message, and I'm sending it to you! .
and sendmail will attempt to send it.
biff — Receive detailed mail notifications at the command line.
mail — Read, compose, and manage mail.
mailx — Process mail messages.
newalias — Install new elm aliases.
pine — A client for using mail and newsgroups.