Learn how to send an email using sendmail command in Linux with complete examples, attachments, and multiple recipients in a few simple commands. Our Live Support Team is always here to help you.
How to Send an Email Using Sendmail Command in Linux
Emails are a crucial part of communication in any Linux environment, whether for system notifications, scripts, or quick messages. Many users want a direct approach to sending emails without relying on heavy email clients. In this guide, we will show you how to send an email using sendmail command in Linux, covering multiple methods, attachments, and examples you can follow immediately.

An Overview
Understanding Sendmail
Sendmail is a robust mail transfer agent (MTA) used to route emails to specific recipients (read more). It works in a Shell environment or within scripts, making it perfect for automated email sending. Before diving into commands, remember that MTAs like Sendmail expect messages in Internet Message Format. For most cases, it is the standard choice for sending simple emails (Linux Sendmail Port 587).
Sending Email Using the Sendmail Command
First, create a file containing your email content:
$ cat /tem/email.txt
Subject: Terminal Email Send
Email Content line 1
Email Content line 2
Next, send the email with this command:
$ sendmail user@example.com < /tem/email.txt
This is the simplest way to send an email using sendmail command in Linux.
Using the Mail Command
You can also send emails via the mail command. For instance:
$ mail -s "Test Subject" user@example.com < /dev/null
To send an attachment, use:
$ mail -a /opt/file.sql -s "Backup File" user@example.com < /dev/null
For multiple recipients:
$ mail -s "Test Email" user@example.com,user2@example.com < /dev/null
Using Mutt Command
Mutt provides advanced email options and attachments:
$ mutt -s "Test Email" user@example.com < /dev/null
Including an attachment:
$ mutt -s "Test Email" -a /opt/backup.sql -- user@example.com < /dev/null
To know more about Sendmail Command in Linux

Advanced Shell Script Using Sendmail
For repeated or automated emails, a shell script can simplify the process:
#!/bin/sh
# sendmail command line options:
# -i - do not treat lines starting with dot specially
# -t - read recipients lists from message headers: TO,CC,BCC
# -v - use verbose mode (describe what is happening)
#
# The empty line separates mail headers from mail body.
# Without -t, recipients should be listed after command line options.
FROM='john.doe@examle.net'
TO='jane.doe@example.com'
/usr/sbin/sendmail -i -t << MESSAGE_END
To: ${TO}
From: ${FROM}
Subject: Example Subject
Hi, this is my message,
and I'm sending it to you!
MESSAGE_END
Note: Sending non-US-ASCII characters requires additional MIME headers. Refer to this guide and RFC 2045 for encoding guidelines.
Alternative Methods to Send Email from Linux Command Line
Transitioning further, there are several alternatives to Sendmail:
Using ssmtp
$ sudo apt-get update
$ sudo apt-get install ssmtp
$ ssmtp username@domain.com
After pressing Enter, type the subject:
Subject: Linux topics of operavps blog
Then type the email body and press Ctrl+D to send.
Using Mailx
$ sudo apt install mailx
$ echo "message body" | mail -s "subject" email_address
Using mpack
$ sudo apt install mpack
$ mpack -s "Your Subject" -a file email_address
Each of these methods offers flexibility depending on whether you want attachments, multiple recipients, or simple messages.
[If needed, Our team is available 24/7 for additional assistance.]
Conclusion
Sending emails directly from Linux is straightforward when you know the right commands. From simple text messages to attachments and automated scripts, learning how to send an email using sendmail command in Linux streamlines communication efficiently. By following the above examples, anyone can quickly integrate email notifications into scripts or system processes, saving time and effort.
With all the options laid out here, Sendmail, Mail, Mutt, ssmtp, Mailx, and mpack, you now have a complete toolkit to manage Linux emails professionally.
