How to Send Email From the Linux Command line?

Question: how to send email?Linux includes a large number of commands commands that allow you to send email from the command line. Here use simple Linux Command Into Send Emails To The Inbox Every Time.

We all know the importance of emails these days for details transfer. There are many free emails service providers which we accustomed for use like ProtonMail, Gmail, Outlook, Yahoo Mail, RediffMail, Zoho, mailx etc, which provides a web interface for sending and receiving emails. But this is not enough, sometimes I as well necessary to send emails from system command line. Big tutorial will allocate you multiple methods to send emails from the Linux command line. This is helpful for successfully sending email between our main shell scripts, any type of the cronjobs or crontab mailx etc.

To send email from the Linux command line, you can use the mail command. Here’s an example of how to send an email with a subject and message body:

echo "This is the message body." | mail -s "This is the subject" [email protected]

In this example, the message body is passed to the echo command, which outputs it to the standard output. The | (pipe) symbol is used to redirect the output to the mail command, which reads the message body from the standard input.

The -s option is used to specify the email subject, and [email protected] is the email address of the recipient.

If you want to send an email with an attachment, you can use the uuencode command to encode the file and include it in the email. Here’s an example:

uuencode /path/to/file.pdf file.pdf | mail -s "This is the subject" [email protected]

In this example, uuencode is used to encode the file /path/to/file.pdf and output it to the standard output. The | symbol is used to redirect the output to the mail command, which reads the encoded file from the standard input and includes it as an attachment in the email.

Note that the mail command may not be available on all Linux systems, and some email providers may reject emails sent from the command line. You may need to use a third-party tool or configure your email client to send email from the command line.

Send Email from the Linux Command Line Examples

step by step Sending email from the Linux echo command line is necessary when you need to make emails from a shell script.You can use any one of the below to successfully send email from the Linux Terminal or CMD command line.

The flow chart below can explain more about that.

send mail html, email client linux, sendemail html, send email from command line, how to send an email with an attachment, send email with smtp, debian mail server, openbsd vps, email server testen
Way + Command List Syntax
implement sendmail
$ sendmail [email protected]  < /tmp/email.txt
implement ‘mail’
$ mail -s "Experiment Subject" [email protected] < /dev/null
implement 'mutt'
$ mutt -s "Experiment Email" [email protected] < /dev/null
implement 'SSMTP'
$ssmtp [email protected]
Subject: Experiment SSMTP Email
Email send test using SSMTP
via SMTP server.
implement 'telnet' Below More Details.....

There are different more Important methods to send emails from the echo command line but here I am sharing one or two options accustomed by most users. You can use choose a public optional option specified below to send email from Linux command line.

1. implement ‘sendmail’ Command

"Sendmail" is a most popular SMTP server accustomed in most of Linux/Unix distribution. Sendmail allows sending email from echo command line. Use below directive to send email using ‘sendmail‘ command.

Created a file with email content:

$cat /tmp/email.txt

Subject: Pakainfo Terminal Email Send

Email send Good Bolly4u 2020 Content is King line 1
Email Great Big Data Content mp3goo line 2

Mail Subject: line will be accustomed as subject for email.

After that you can send email using the below simple great command.

$ sendmail [email protected]  < /tmp/email.txt

2. implement ‘mail’ Command

Here, You can step by step using a mail CMD echo command is few fresh command to send emails from Linux terminal. Use one or two of below very easy and genuine examples to send an email.

$ mail -s "Experiment Pakainfo Mail Subject" [email protected] < /dev/null

-s is accustomed for defining subject for email.

as well as, you can send an attachment successfully with this best command. Use -a stands for a mailx with -A stands for a for mailutils.

$ mail -a /opt/backup.sql -s "Backup File" [email protected] < /dev/null

I use a -a is accustomed for file or Images or any types of the attachments. Use -A for debian based Live systems, which uses simple extra added the mailutils package.

as well, I can included special char like as comma separated emails to proper send the email to multiple users as a recipients together successfully.

$ mail -s "Experiment Email"  [email protected],[email protected] < /dev/null
mail x, mutt send html email, inux email, send email via command line, unix send email with attachment, smtp mail commands, install smtp server ubuntu, send test email online, linux smtp server, sending sms from linux, setup smtp server linux
5 Ways to Send Email From Linux Command Line

3. implement 'mutt' command

Mutt is basically accustomed for reading emails from Terminal to Linux terminal from local customer mailboxes, as well as helpful to read emails from POP/IMAP servers. Mutt command is little similar to mail echo command. Use one or two of below some best helpful genuine examples to proper send an email successfully.

$ mutt -s "Experiment Email" [email protected] < /dev/null

Send an email including an attachment

$ mutt  -s "Experiment Email" -a /opt/backup.sql [email protected] < /dev/null

4. implement 'SSMTP' Command

sSMTP allows customers to send emails for newbie from SMTP server from Terminal to Linux command line. For example to send an email to customer [email protected] use below command. And then you can type your main Great subject of the email as below with a Focus keyword put in your very attractive Subject Line. After that type your some message to be sent to the customer, After last step to you can finishing your message press simple CTRL+d (^d) to send the email.

$ ssmtp [email protected]
Subject: Experiment Pakainfo SSMTP Email
Email send test using SSMTP
via SMTP server.

5. implement 'telnet' Command

As per According to me, all the system for Main Root Level administrators use telnet any type of the command to simply you can test purpose remote port check the data connectivity easyly test or signin means Login system to the server based remotely. we know Most of the case beginner devloper in Linux Terminal to doesn't all about know that I can send best way to email using telnet as well, which is the more better level to any type of the troubleshoot email sending problems. Below is very easy and tiny an example of step by step email sending.

Red marked text is the customer input and remaining is the responses of that commands.

$ telnet localhost smtp

Connected to localhost.localdomain (
Escape character is '^]'.
220 ESMTP Sendmail 8.13.8/8.13.8; FRI, 29 Apr 2019 08:09:59 -0400
250 Hello [], pleased free to Search Results Web results Bolly4u 2019
mail from: [email protected]
250 2.1.0 [email protected]... Sender ok
rcpt to: [email protected]
250 2.1.5 [email protected]... Recipient ok
354 press the Enter mail, end with "." on a line by coding or put the itself
Gretting name,
It is a simple testing for the v2 Mail Send - Send Email Using HTTP
Thanks a lot
250 2.0.0 r9M95xgc014513 some Message accepted for mail delivery
221 2.0.0 closing connection
Connection closed by foreign host.

Sending email to multiple recipients

If you want to simple "recipients" Based send email from the Terminal using Linux command line to a big group of recipients, you can always use a loop to make the job easier as in this example using mutt.

$ for notify in `cat notifys`
    mutt -s "about the Minutes from May offical work for Pakainfo" $notify < May_minutes


There are quite a Most Imp 5 Ways to Send Email From Linux Terminal to Command Line. Some tools allocate quite a 5 simple and easy options.

Thank you for using this Post. I shall include more some methods soon with this all the helpful commands list. I as well request you to help me with more Advanced Level More commands which you free to know as well as not listed above please commenting.

Leave a Comment