sendmail – Widely used Email Server

sendmail is a widely used Mail Transfer Agent (MTA) that is responsible for routing and delivering email messages between mail servers. It is a powerful and flexible tool that allows you to send emails from the command line or through scripts. sendmail is also the default MTA on many Linux distributions and is commonly used in conjunction with other mail-related utilities such as mail, mailx, and mutt.

Overview

The sendmail command is used to send email messages from the command line. The basic syntax of the command is as follows:

sendmail [options] recipient(s)

Where recipient(s) is the email address(es) of the person(s) you want to send the email to. You can specify multiple recipients by separating them with commas.

To send an email message, you need to provide the message content on the command line or through standard input. The easiest way to do this is to use a here document. For example:

sendmail user@example.com <<EOF
Subject: Test Email
This is a test email.
EOF

This will send an email message with the subject “Test Email” and the message body “This is a test email.” to the user at user@example.com.

You can also specify the sender address using the -f option. For example:

sendmail -f sender@example.com user@example.com <<EOF
Subject: Test Email
This is a test email.
EOF

This will send the email message from the address sender@example.com.

Options

The following table lists the available options for the sendmail command:

Option Description
-Am Use the specified mailer.
-Bbodytype Specify the body type of the message.
-bd Run in daemon mode.
-bi Initialize the alias database.
-bm Run in “send and queue” mode.
-bs Run in “send only” mode.
-bt Test mode: parse and print addresses only.
-bv Verify addresses only.
-Cconfigfile Use the specified configuration file.
-dlevel Set debugging level.
-Dmacro=value Define a macro with a value.
-faddress Specify the sender address.
-Ffullname Specify the sender’s full name.
-hhostname Specify the hostname.
-i Ignore dots in message body.
-Lloglevel Set logging level.
-N Do not do DNS lookups.
-n Do not alias addresses.
-Ooption=value Set an option with a value.
-odb Debugging output for the queue.
-odq Debugging output for the queue.
-oe Debugging output for errors.
-oi Ignore dots in message body.
-oQ Quote the message body.
-oR Do not quote the message body.
-os Use system configuration file.
-OT Trace delivery of message.
-oX Do not add MIME header.
-q Process the mail queue.
-qI Process the incoming mail queue.
-qR Process the deferred mail queue.
-qS Process the sent mail queue.
-qf Process a specific queue file.
-qg Process the frozen mail queue.
-qm Process the main mail queue.
-qp Print the contents of a queue file.
-qs Print the status of the mail queue.
-qS Process the sent mail queue.
-qX Process the corrupt mail queue.
-r Use the return address as the sender address.
-t Read message for recipients from standard input.
-v Verbose output.
-V Print version information.
-x Do not send mail.

Troubleshooting Tips

  • If you are having trouble sending email messages, check the mail log file for errors. On most Linux distributions, the mail log file is located at /var/log/mail.log.
  • Make sure that the recipient email address is valid and that the recipient’s mail server is properly configured to receive email.
  • If you are using sendmail in a script, make sure that the script has proper permissions to access the sendmail command and that the command is in the system’s PATH.

Notes

  • sendmail is a powerful and flexible tool for sending email messages from the command line, but it can be complex and difficult to use for beginners.
  • There are many other mail-related utilities available on Linux, such as mail, mailx, and mutt, that provide simpler and more user-friendly interfaces for sending and receiving email.