# Linux Administration:Mails & Lists

### *Sendmail*

1. Sendmail is a general purpose e-mail routing facility that supports many kinds of mail-transfer and delivery methods, including the **SMTP (Simple Mail Transfer Protocol)** used for e-mail transport over the Internet.
    
2. 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.
    
3. **Sendmail** is used only to deliver pre-formatted messages.
    
    ### Setting Up Sendmail with SSMTP Package
    
    **Step 1.** Check if Command Line Mailer Package is Installed
    
    ```plaintext
    sudo apt install <selected package> #IF NOT INSTALLED
    ```
    
    **Step 2.** Installing Sendmail Command Line Mailer Package
    
    ```plaintext
         sudo apt install ssmtp
    ```
    
    **Step 3.** Verify the Installation
    
    ```plaintext
    echo "Subject: hello" | sendmail test@example.com
    ```
    
    **Step 4.** Configuring SSMTP
    
    Let's locate the config file at `/etc/ssmtp/ssmtp.conf`. Here, you should put the code below to configure an SMTP relay:
    
    ```plaintext
        UseSTARTTLS=YES
    	root=<your-email-address>
    	mailhub=smtp.gmail.com:587
    	AuthUser=<your-account's-user-name>
    	AuthPass=<your-account's-password>
    ```
    
    ## Sending Email Using the SSMTP Command
    
    As such, SSMTP allows users to transfer emails through an SMTP server from the Linux command line. It provides the means to connect to a mailhub with a proper configuration file. If your config file was set up right, all your worries regarding command line email sending can disappear.
    
    **Basic Implementation of the SSTMP command:**
    
    If you just use SSMTP, the command should look as follows:
    
    ```plaintext
          ssmtp  test@example.com < mail.txt
    ```
    
    Following the `ssmtp` command, you should put the recipient address, then you can include a file that will show in the email body. Here you can define headers for the message, list further recipients and set the content type. This way you can send HTML emails. SSMTP will interpret your message and use the provided values properly. Here is an example of an HTML you might send:
    
    ```plaintext
    	Cc: example@edmdesigner.com
    	Subject: This is an HTML email
    	From: developer@example.com
    	Content-Type: text/html; charset="utf8"
    
    
    	html>
    	<body>
    	<div style="
    		background-color:
    		#abcdef; width: 300px;
    		height: 300px;
    		">
    	</div>
    	You can add any valid email HTML here.
    	</body>
    	</html>
    ```
    
    You can't really give further options with SSMTP as they are not respected by its minimalistic design.
    
    **Troubleshooting:**
    
    In case you run into the following error on the command line:
    
    ```plaintext
          ssmtp: Authorization failed (534 5.7.9  
          http://support.google.com/accounts/bin/answer.py?answer=185833 
          bk8sm8525341pad.28 - gsmtp)
    ```
    
    ## Sending Email Using the Sendmail Command
    
    ```plaintext
          echo "Subject: hello" | sendmail -v test@example.com < mail.txt
    ```
    
    I threw in the `-v` argument, which will make the communication between the mail server and your mail transfer agent visible.
    
    ## Sending Email Using CURL Command
    
    ```plaintext
          sudo apt install curl
    ```
    
    **Advanced implementation for email sending with CURL:**
    
    **Basic implementation for email sending with CURL:**
    
    ```plaintext
    curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
      --mail-from 'developer@gmail.com' --mail-rcpt 'edm-user@niceperson.com' \
      --upload-file mail.txt --user 'developer@gmail.com:your-accout-password'
    ```
    
    **Advanced implementation for email sending with CURL:**
    
    ```plaintext
    curl -sv --user 'api:key-7e55d003b...f79accd31a' \
        https://api.mailgun.net/v3/sandbox21a78f824...3eb160ebc79.mailgun.org/messages \
        -F from='Excited User <developer@yourcompany.com>' \
        -F to=sandbox21a78f824...3eb160ebc79.mailgun.org \
        -F to=user@gmail.com \
        -F subject='Hello' \
        -F text='Testing some Mailgun awesomeness!' \
       --form-string html='<h1>EDMdesigner Blog</h1><br /><cite>This tutorial helps me understand email sending from Linux console</cite>' \
        -F attachment=@logo2yellow.jpg
    ```
    
    ## **Syntax**
    
    ```plaintext
    sendmail [flags] [address ...]
    ```
    
    ## **Alternate syntax**
    
    **Sendmail** can also be invoked, with special functionality, using the following commands.
    
    ```plaintext
    newaliases
    ```
    
    ```plaintext
    mailq [-v]
    ```
    
    ```plaintext
    hoststat
    ```
    
    ```plaintext
    purgestat
    ```
    
    ```plaintext
    smtpd
    ```
    
    ## **Parameters**
    
    <table><tbody><tr><td colspan="1" rowspan="1"><p><strong>-Ac</strong></p></td><td colspan="1" rowspan="1"><p>Use <a target="_blank" rel="noopener noreferrer nofollow" href="http://submit.cf" style="pointer-events: none"><strong>submit.cf</strong></a> even if the operation mode does not indicate an initial mail submission.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-Am</strong></p></td><td colspan="1" rowspan="1"><p>Use <a target="_blank" rel="noopener noreferrer nofollow" href="http://sendmail.cf" style="pointer-events: none"><strong>sendmail.cf</strong></a> even if the operation mode indicates an initial mail submission.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-B</strong><em>type</em></p></td><td colspan="1" rowspan="1"><p>Set the body type to <em>type</em>. Current legal values are <strong>7BIT</strong> or <strong>8BITMIME</strong>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-ba</strong></p></td><td colspan="1" rowspan="1"><p>Go into <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/a/arpanet.htm" style="pointer-events: none">ARPANET</a> mode. All input lines must end with a <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/c/cr.htm" style="pointer-events: none">CR</a>-<a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/l/lf.htm" style="pointer-events: none">LF</a>, 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.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bd</strong></p></td><td colspan="1" rowspan="1"><p>Run as a <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/d/daemon.htm" style="pointer-events: none">daemon</a>. <strong>sendmail</strong> will fork and run in background listening on socket 25 for incoming SMTP connections. This is normally run from <strong>/etc/rc</strong>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bD</strong></p></td><td colspan="1" rowspan="1"><p>Same as <strong>-bd</strong>, except it runs in foreground.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bh</strong></p></td><td colspan="1" rowspan="1"><p>Print the persistent host status <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/d/database.htm" style="pointer-events: none">database</a>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bH</strong></p></td><td colspan="1" rowspan="1"><p><a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/p/purge.htm" style="pointer-events: none">Purge</a> expired entries from the persistent host status database.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bi</strong></p></td><td colspan="1" rowspan="1"><p>Initialize the alias database.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bm</strong></p></td><td colspan="1" rowspan="1"><p>Deliver mail in the usual way (default).</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bp</strong></p></td><td colspan="1" rowspan="1"><p>Print a listing of the <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/q/queue.htm" style="pointer-events: none">queue</a>(s).</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bP</strong></p></td><td colspan="1" rowspan="1"><p>Print number of entries in the queue(s); only available with shared memory support.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bs</strong></p></td><td colspan="1" rowspan="1"><p>Use the SMTP <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/p/protocol.htm" style="pointer-events: none">protocol</a> as described in <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/r/rfc.htm" style="pointer-events: none">RFC</a> 821 on standard input and output. This flag implies all the operations of the <strong>-ba</strong> flag that are compatible with SMTP.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bt</strong></p></td><td colspan="1" rowspan="1"><p>Run in address test mode. This mode reads addresses and shows the steps in parsing; it is used for <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/d/debug.htm" style="pointer-events: none">debugging</a> configuration tables.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-bv</strong></p></td><td colspan="1" rowspan="1"><p>Verify names only; do not try to collect or deliver a message. Verify mode is normally used for validating users or mailing lists.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-C</strong><em>file</em></p></td><td colspan="1" rowspan="1"><p>Use alternate configuration file. <strong>sendmail</strong> gives up any enhanced (<a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/s/suid.htm" style="pointer-events: none">set-user-ID</a> or set-group-ID) privileges if an alternate configuration file is specified.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-D</strong> <em>logfile</em></p></td><td colspan="1" rowspan="1"><p>Send debugging output to the indicated <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/l/log.htm" style="pointer-events: none">log</a> file instead of stdout.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-d</strong><em>category</em><strong>.</strong><em>level</em>...</p></td><td colspan="1" rowspan="1"><p>Set the debugging flag for <em>category</em> to <em>level</em>. The <em>category</em> is either an <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/i/integer.htm" style="pointer-events: none">integer</a> or a name specifying the topic, and <em>level</em> 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 found in the <strong>TRACEFLAGS</strong> file in the <strong>sendmail</strong> <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/s/source.htm" style="pointer-events: none">source</a> distribution. The option <strong>-d0.1</strong> prints the version of <strong>sendmail</strong> and the options used during the compile. Most other categories are only useful with, and documented in, <strong>sendmail</strong>'s source code.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-F</strong><em>fullname</em></p></td><td colspan="1" rowspan="1"><p>Set the full name of the sender.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-f</strong><em>name</em></p></td><td colspan="1" rowspan="1"><p>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. <strong>-f</strong> should only be used by "trusted" users (normally <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/r/root.htm" style="pointer-events: none">root</a>, <strong>daemon</strong>, and <strong>network</strong>) or if the person you are trying to become is the same as the person you are. Otherwise, an "X-Authentication-Warning" header is added to the message.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-G</strong></p></td><td colspan="1" rowspan="1"><p>Relay (gateway) submission of a message, e.g., when <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/unix/umail.htm" style="pointer-events: none">rmail</a> calls <strong>sendmail</strong>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-h</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>Set the hop count to <em>N</em>. 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.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-i</strong></p></td><td colspan="1" rowspan="1"><p>Ignore dots alone on lines by themselves in incoming messages. This should be set if you are reading data from a file.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-L</strong> <em>tag</em></p></td><td colspan="1" rowspan="1"><p>Set the identifier used in <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/s/syslog.htm" style="pointer-events: none">syslog</a> messages to the supplied <em>tag</em>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-N</strong> <em>dsn</em></p></td><td colspan="1" rowspan="1"><p>Set delivery status notification conditions to <em>dsn</em>, which can be "<strong>never</strong>" for no notifications, or a comma separated list of the values "<strong>failure</strong>" to be notified if delivery failed, "<strong>delay</strong>" to be notified if delivery is delayed, and "<strong>success</strong>" to be notified when the message is successfully delivered.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-n</strong></p></td><td colspan="1" rowspan="1"><p>Don't do aliasing.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-O</strong> <em>option</em><strong>=</strong><em>value</em></p></td><td colspan="1" rowspan="1"><p>Set option <em>option</em> to the specified <em>value</em>. This form uses long names. See below for more details.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-o</strong><em>x</em> <em>value</em></p></td><td colspan="1" rowspan="1"><p>Set option <em>x</em> to the specified <em>value</em>. This form uses single <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/c/charact.htm" style="pointer-events: none">character</a> names only.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-p</strong><em>protocol</em></p></td><td colspan="1" rowspan="1"><p>Set the name of the protocol used to receive the message. This can be a simple protocol name such as "<strong>UUCP</strong>" or a protocol and hostname, such as "<strong>UUCP:ucbvax</strong>".</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong>[<em>time</em>]</p></td><td colspan="1" rowspan="1"><p>Process saved messages in the queue at given intervals. If <em>time</em> is omitted, process the queue once. The <em>time</em> is given as a tagged number, with "<strong>s</strong>" being seconds, "<strong>m</strong>" being minutes (default), "<strong>h</strong>" being hours, "<strong>d</strong>" being days, and "<strong>w</strong>" being weeks. For example, "<strong>-q1h30m</strong>" or "<strong>-q90m</strong>" would both set the <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/t/timeout.htm" style="pointer-events: none">timeout</a> to one hour thirty minutes. By default, <strong>sendmail</strong> runs in the background. This option can be used safely with <strong>-bd</strong>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-qp</strong>[<em>time</em>]</p></td><td colspan="1" rowspan="1"><p>Similar to <strong>-q</strong><em>time</em>, except that instead of periodically <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/f/fork.htm" style="pointer-events: none">forking</a> a <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/p/parechil.htm" style="pointer-events: none">child</a> to process the queue, <strong>sendmail</strong> forks a single persistent child for each queue that alternates between processing the queue and sleeping. The sleep time is given as the <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/a/argument.htm" style="pointer-events: none">argument</a>; it defaults to 1 second. The process always sleeps at least 5 seconds if the queue was empty in the previous queue run.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong><em>f</em></p></td><td colspan="1" rowspan="1"><p>Process saved messages in the queue once and do not fork, but run in the foreground.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-qG</strong><em>name</em></p></td><td colspan="1" rowspan="1"><p>Process jobs in queue group called <em>name</em> only.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong>[<strong>!</strong>]<strong>I</strong><em>substr</em></p></td><td colspan="1" rowspan="1"><p>Limit processed jobs to those containing <em>substr</em> as a <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/s/substring.htm" style="pointer-events: none">substring</a> of the queue id or not when <strong>!</strong> is specified.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong>[<strong>!</strong>]<strong>Q</strong><em>substr</em></p></td><td colspan="1" rowspan="1"><p>Limit processed jobs to quarantined jobs containing <em>substr</em> as a substring of the quarantine reason or not when <strong>!</strong> is specified.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong>[<strong>!</strong>]<strong>R</strong><em>substr</em></p></td><td colspan="1" rowspan="1"><p>Limit processed jobs to those containing <em>substr</em> as a substring of one of the recipients or not when <strong>!</strong> is specified.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-q</strong>[<strong>!</strong>]<strong>S</strong><em>substr</em></p></td><td colspan="1" rowspan="1"><p>Limit processed jobs to those containing <em>substr</em> as a substring of the sender or not when <strong>!</strong> is specified.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-Q</strong>[<em>reason</em>]</p></td><td colspan="1" rowspan="1"><p>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.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-R</strong> <em>return</em></p></td><td colspan="1" rowspan="1"><p>Set the amount of the message to be returned if the message <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/b/bounce.htm" style="pointer-events: none">bounces</a>. The return parameter can be "<strong>full</strong>" to return the entire message or "<strong>hdrs</strong>" to return only the headers. In the latter case, local bounces return only the headers.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-r</strong><em>name</em></p></td><td colspan="1" rowspan="1"><p>An alternate and obsolete form of the <strong>-f</strong> flag.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-t</strong></p></td><td colspan="1" rowspan="1"><p>Read message for recipients. <strong>To:</strong>, <strong>Cc:</strong>, and <strong>Bcc:</strong> lines will be scanned for recipient addresses. The <strong>Bcc:</strong> line are deleted before transmission.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-V</strong> <em>envid</em></p></td><td colspan="1" rowspan="1"><p>Set the original envelope id. This is propagated across SMTP to servers that support DSNs and is returned in DSN-compliant error messages.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-v</strong></p></td><td colspan="1" rowspan="1"><p>Go into <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/v/verbose.htm" style="pointer-events: none">verbose</a> mode. Alias expansions will be announced, etc.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>-X</strong> <em>logfile</em></p></td><td colspan="1" rowspan="1"><p>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.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>--</strong></p></td><td colspan="1" rowspan="1"><p>Stop processing command flags and use the rest of the arguments as addresses.</p></td></tr></tbody></table>
    
    ### **Options**
    
    There are also many processing options that can be set. Normally these are only used by a [system administrator](https://www.computerhope.com/jargon/r/root.htm). Options may be set either on the [command line](https://www.computerhope.com/jargon/c/commandi.htm) 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:
    
    <table><tbody><tr><td colspan="1" rowspan="1"><p><strong>AliasFile=</strong><em>file</em></p></td><td colspan="1" rowspan="1"><p>Use alternate alias file.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>HoldExpensive</strong></p></td><td colspan="1" rowspan="1"><p>On mailers that are considered "expensive" to connect to, don't initiate immediate connection. This requires queueing.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>CheckpointInterval=</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>Checkpoint the queue file after every <em>N</em> successful deliveries (default <strong>10</strong>). This avoids excessive duplicate deliveries when sending to long mailing lists interrupted by system crashes.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>DeliveryMode=</strong><em>x</em></p></td><td colspan="1" rowspan="1"><p>Set the delivery mode to <em>x</em>. Delivery modes are "<strong>i</strong>" for interactive (synchronous) delivery, "<strong>b</strong>" for background (<a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/a/asynchro.htm" style="pointer-events: none">asynchronous</a>) delivery, "<strong>q</strong>" for queue only; i.e., actual delivery is done the next time the queue is run, and "<strong>d</strong>" for deferred: the same as "<strong>q</strong>" except that database lookups for maps which have set the <strong>-D</strong> option (default for the host map) are avoided.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>ErrorMode=</strong><em>x</em></p></td><td colspan="1" rowspan="1"><p>Set error processing to mode <em>x</em>. Valid modes are "<strong>m</strong>" to mail back the error message, "<strong>w</strong>" to "write" back the error message (or mail it back if the sender is not logged in), "<strong>p</strong>" to print the errors on the <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/t/terminal.htm" style="pointer-events: none">terminal</a> (default), "<strong>q</strong>" to throw away error messages (only exit status is returned), and "<strong>e</strong>" to do special processing for BerkNet. If the text of the message is not mailed back by modes "<strong>m</strong>" or "<strong>w</strong>" and if the sender is local to this machine, a copy of the message is appended to the file <strong>dead.letter</strong> in the sender's <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/h/homedir.htm" style="pointer-events: none">home directory</a>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>SaveFromLine</strong></p></td><td colspan="1" rowspan="1"><p>Save Unix-style <strong>From</strong> lines at the front of messages.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>MaxHopCount=</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>The maximum number of times a message is allowed to "hop" before we decide it's in a loop.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>IgnoreDots</strong></p></td><td colspan="1" rowspan="1"><p>Do not take dots on a line by themselves as a message terminator.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>SendMimeErrors</strong></p></td><td colspan="1" rowspan="1"><p>Send error messages in <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/m/mime.htm" style="pointer-events: none">MIME</a> format. If not set, the DSN (Delivery Status Notification) SMTP extension is disabled.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>ConnectionCacheTimeout=</strong><em>timeout</em></p></td><td colspan="1" rowspan="1"><p>Set connection cache timeout.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>ConnectionCacheSize=</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>Set connection cache size.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>LogLevel=</strong><em>n</em></p></td><td colspan="1" rowspan="1"><p>The log level.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>MeToo=False</strong></p></td><td colspan="1" rowspan="1"><p>Don't send to "me" (the sender) if I am in an alias expansion.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>CheckAliases</strong></p></td><td colspan="1" rowspan="1"><p>Validate the right side of aliases during a <strong>newaliases</strong> command.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>OldStyleHeaders</strong></p></td><td colspan="1" rowspan="1"><p>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.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>QueueDirectory=</strong><em>queuedir</em></p></td><td colspan="1" rowspan="1"><p>Select the directory where to queue messages.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>StatusFile=</strong><em>file</em></p></td><td colspan="1" rowspan="1"><p>Save statistics in the named <em>file</em>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Timeout.queuereturn=</strong><em>time</em></p></td><td colspan="1" rowspan="1"><p>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 time, failed messages will be returned to the sender. The default is five days.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>UserDatabaseSpec=</strong><em>userdatabase</em></p></td><td colspan="1" rowspan="1"><p>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 <strong>sendmail</strong> does not have the <strong>USERDB</strong> option compiled in.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>ForkEachJob</strong></p></td><td colspan="1" rowspan="1"><p>Fork each job during queue runs. May be convenient on memory-poor machines.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>SevenBitInput</strong></p></td><td colspan="1" rowspan="1"><p>Strip incoming messages to seven bits.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EightBitMode=</strong><em>mode</em></p></td><td colspan="1" rowspan="1"><p>Set the handling of eight bit input to seven bit destinations to mode: <strong>m</strong> (mimefy) will convert to seven-bit MIME format, <strong>p</strong> (pass) will pass as eight bits (but violates protocols), and <strong>s</strong> (strict) will bounce the message.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>MinQueueAge=</strong><em>timeout</em></p></td><td colspan="1" rowspan="1"><p>Sets how long a job must ferment in the queue between attempts to send it.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>DefaultCharSet=</strong><em>charset</em></p></td><td colspan="1" rowspan="1"><p>Sets the default character set used to label 8-bit data that is not otherwise labelled.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>DialDelay=</strong><em>sleeptime</em></p></td><td colspan="1" rowspan="1"><p>If opening a connection fails, sleep for <em>sleeptime</em> seconds and try again. Useful on dial-on-demand sites.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>NoRecipientAction=</strong><em>action</em></p></td><td colspan="1" rowspan="1"><p>Set the behaviour when there are no recipient headers (<strong>To:</strong>, <strong>Cc:</strong> or <strong>Bcc:</strong>) in the message to <em>action</em>: <strong>none</strong> leaves the message unchanged, <strong>add-to</strong> adds a <strong>To:</strong> header with the envelope recipients, <strong>add-apparently-to</strong> adds an <strong>Apparently-To:</strong> header with the envelope recipients, <strong>add-bcc</strong> adds an empty <strong>Bcc:</strong> header, and <strong>add-to-undisclosed</strong> adds a header reading `<strong>To: undisclosed-recipients:;</strong>'.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>MaxDaemonChildren=</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>Sets the maximum number of children that an incoming SMTP daemon allows to spawn at any time to <em>N</em>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>ConnectionRateThrottle=</strong><em>N</em></p></td><td colspan="1" rowspan="1"><p>Sets the maximum number of connections per second to the SMTP port to <em>N</em>.</p></td></tr></tbody></table>
    
    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 that [pipes](https://www.computerhope.com/jargon/p/pipe.htm) the mail. It may be necessary to quote the name to keep **sendmail** from suppressing the blanks from between arguments. For example, a common alias is:
    
    ```plaintext
    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:
    
    ```plaintext
    poets: ":include:/usr/local/lib/poets.list"
    ```
    
    would read **/usr/local/lib/poets.list** for the list of addresses making up the group.
    
    ## **Exit status**
    
    Sendmail returns an exit status describing what it did. The exit codes are listed below, and defined in **&lt;sysexits.h&gt;**.
    
    <table><tbody><tr><td colspan="1" rowspan="1"><p><strong>EX_OK</strong></p></td><td colspan="1" rowspan="1"><p>Successful completion on all addresses.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_NOUSER</strong></p></td><td colspan="1" rowspan="1"><p>Username not recognized.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_UNAVAILABLE</strong></p></td><td colspan="1" rowspan="1"><p>Catchall meaning necessary resources were not available.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_SYNTAX</strong></p></td><td colspan="1" rowspan="1"><p>Syntax error in address.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_SOFTWARE</strong></p></td><td colspan="1" rowspan="1"><p>Internal software error, including bad arguments.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_OSERR</strong></p></td><td colspan="1" rowspan="1"><p>Temporary <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/o/os.htm" style="pointer-events: none">operating system</a> error, such as "cannot fork".</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_NOHOST</strong></p></td><td colspan="1" rowspan="1"><p><a target="_blank" rel="noopener noreferrer nofollow" href="https://www.computerhope.com/jargon/h/hostname.htm" style="pointer-events: none">Hostname</a> not recognized.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>EX_TEMPFAIL</strong></p></td><td colspan="1" rowspan="1"><p>Message could not be sent immediately, but was queued.</p></td></tr></tbody></table>
    
    ## **Alternate invocations**
    
    If invoked as **newaliases**, sendmail will rebuild the alias database.
    
    If invoked as **mailq**, sendmail prints the contents of the mail queue.
    
    If invoked as **hoststat**, sendmail prints the persistent host status database.
    
    If invoked as **purgestat**, sendmail purges expired entries from the persistent host status database.
    
    If invoked as **smtpd**, sendmail acts as a daemon, as if the **\-bd** option were specified.
    
    ## **Files**
    
    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.
    
    <table><tbody><tr><td colspan="1" rowspan="1"><p><strong>/etc/mail/aliases</strong></p></td><td colspan="1" rowspan="1"><p>raw data for alias names</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>/etc/mail/aliases.db</strong></p></td><td colspan="1" rowspan="1"><p>database of alias names</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>/etc/mail/sendmail.cf</strong></p></td><td colspan="1" rowspan="1"><p>configuration file</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>/etc/mail/helpfile</strong></p></td><td colspan="1" rowspan="1"><p>help file</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>/etc/mail/statistics</strong></p></td><td colspan="1" rowspan="1"><p>collected statistics</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>/var/spool/mqueue/*</strong></p></td><td colspan="1" rowspan="1"><p>temp files</p></td></tr></tbody></table>
    
    ## **Examples**
    
    ```plaintext
    sendmail user@example.com
    ```
    
    **sendmail** will read your e-mail from standard input, and attempt to send the e-mail when you enter a single dot ("**.**") on a new line and press [<kbd>Enter</kbd>](https://www.computerhope.com/jargon/e/enterkey.htm). For example, after running the above command, you could type:
    
    ```plaintext
    From: me@myhost.com
    To: user@example.com
    Hi, this is my message, and I'm sending it to you!
    .
    ```
    
    and **sendmail** attempts to send it.
    
    ## **Related commands**
    
    [**biff**](https://www.computerhope.com/unix/ubiff.htm) — Receive detailed mail notifications at the command line.  
    [**mail**](https://www.computerhope.com/unix/umail.htm) — Read, compose, and manage mail.  
    [**mailx**](https://www.computerhope.com/unix/umailx.htm) — Process mail messages.  
    [**newalias**](https://www.computerhope.com/unix/unewalia.htm) — Install new elm aliases.  
    [**pine**](https://www.computerhope.com/unix/upine.htm) — A client for using mail and newsgroups.
    
    ### *Using Sendmail*
    
    **Configuration Settings**
    
    **DNS Settings**
    
    1. We first want to make sure that mail will be sent to our machine. We assume that we have properly configured a domain called [seafront.bar](http://seafront.bar) with BIND 8 or 9. Let's make sure that the zone file for this domain has an MX record pointing to our system.
        
    
    For example if our machine is called test1 and has the IP 192.168.246.12 then we need the following lines:
    
    ```plaintext
    seafront.bar.	IN	MX 10	test1.seafront.bar.
    test1.seafront.bar.	IN	A	192.168.246.12
    ```
