LinuxCommandLibrary

sendmail

Send email messages

TLDR

Send a message with the content of message.txt to the mail directory of local user username

$ sendmail [username] < [message.txt]
copy

Send an email from you@yourdomain.com (assuming the mail server is configured for this) to test@gmail.com containing the message in message.txt
$ sendmail -f [you@yourdomain.com] [test@gmail.com] < [message.txt]
copy

Send an email from you@yourdomain.com (assuming the mail server is configured for this) to test@gmail.com containing the file file.zip
$ sendmail -f [you@yourdomain.com] [test@gmail.com] < [file.zip]
copy

SYNOPSIS

sendmail [flags] [address ...]
sendmail -bd [flags]
sendmail -bi
sendmail -bp
sendmail -bt
sendmail -bv address ...
sendmail -q [interval]

PARAMETERS

-bd
    Run as a daemon, waiting for incoming mail connections.

-bi
    Initialize the aliases database (run newaliases).

-bp
    Print the contents of the mail queue.

-bt
    Run in address test mode, allowing interactive testing of address parsing and rewrite rules.

-bv address ...
    Verify that an address is valid, but do not attempt to deliver it.

-q [interval]
    Process the queue. If an interval is given (e.g., 30m), run as a queue processing daemon, waking up every interval to process the queue.

-t
    Read message for recipients from the To:, Cc:, and Bcc: headers.

-i or -oi
    Ignore dots on a line by themselves in incoming messages. This is generally recommended.

-v
    Go into verbose mode. Display the delivery steps.

-oXvalue
    Set option X to value. Many internal options can be configured this way.

-f sender
    Set the sender (envelope-from) address. Useful for automated scripts.

DESCRIPTION

sendmail is a venerable and powerful Mail Transfer Agent (MTA) widely used on Unix-like systems for routing and delivering email. It functions as a core component of the email infrastructure, handling the complex process of sending and receiving messages between different mail servers and local users. Known for its extensive configurability and adherence to email standards, sendmail can manage various aspects of mail flow, including resolving recipient addresses, queuing messages, and applying various processing rules. While still widely deployed, its complexity and steep learning curve have led to the rise of more user-friendly alternatives like Postfix and Exim. However, understanding sendmail remains fundamental for anyone managing legacy systems or complex email environments.

CAVEATS

sendmail is notoriously complex to configure, primarily due to its reliance on the sendmail.cf configuration file, which uses a cryptic and powerful macro-based language. This complexity can lead to misconfigurations that expose security vulnerabilities or cause mail delivery issues. Historically, sendmail has had a reputation for security flaws, though most critical issues have been patched over time. Debugging mail flow issues with sendmail can be challenging due to its intricate internal workings and extensive logging. Modern alternatives like Postfix and Exim are often preferred for their simpler configuration and enhanced security posture, making sendmail less common in new deployments.

CONFIGURATION FILES

The primary configuration file for sendmail is /etc/mail/sendmail.cf (or often just /etc/sendmail.cf), which is generated from a more human-readable .mc (m4 configuration) file. Other important files include /etc/mail/aliases (for local mail redirection) and the mail queue directory (e.g., /var/spool/mqueue).

EMAIL FLOW

When a message is submitted to sendmail (either by a local user, an application, or another mail server), it goes through a series of steps: address parsing and rewriting, rule-set processing, queueing, and finally, delivery (either local or remote). sendmail uses its extensive set of rules in sendmail.cf to determine how to handle each message.

HISTORY

sendmail was originally written by Eric Allman at the University of California, Berkeley, in the early 1980s as part of the BSD operating system. It quickly became the dominant Mail Transfer Agent (MTA) in the Unix world and was instrumental in the early growth of the internet's email infrastructure. Its design was revolutionary for its time, providing robust and flexible mail routing capabilities. For decades, it was the de-facto standard for email servers. While still widely used, its development has slowed, and its market share has declined with the rise of newer MTAs that offer simpler configuration and often better performance for common use cases.

SEE ALSO

mail(1), mailx(1), newaliases(8), makemap(8), procmail(1), postfix(1), exim(8)

Copied to clipboard