Trending News


5 Easy Ways to Send An email from the Linux Command Line [ Ultimate Guide ]
How To

5 Easy Ways to Send An email from the Linux Command Line [ Ultimate Guide ] 

Emails are important for information transfer these days, as we all know. Many free email service providers, such as Gmail, Yahoo, RediffMail, and others, offer a web interface for sending and receiving emails, which we used.

Table of Contents

But this is not often enough; we still need to send emails from the system command line on occasion. This guide will show you 5 Ways to Send An email from the Linux Command-Line. This is useful for sending emails from shell scripts, cronjobs, and other automated processes.

There are many ways to send emails from the command line, so I will go through a few that most people use. To send an email from the Linux command line, you can use either of the options mentioned below.

1. Using the Linux Command Line ‘sendmail’

Sendmail is a commonly used SMTP server that is included with almost every Linux/Unix distribution. Sendmail is a Linux command-line program that helps you to send an email. To send an email using the Linux command ‘sendmail‘, follow the steps below.

Create a file with the following email content:

					cat /tmp/email.txt

Subject: Terminal Email Send

Email Content line 1
Email Content line 2

Subject: The subject line will be used as the email’s subject.

Now use the following command to send an email.

					sendmail  < /tmp/email.txt

2. Using the Linux ‘mail’ Command

The most popular command for sending emails from a Linux terminal is mail. To send an email, use a few of the examples below.

					mail -s "Test Subject" < /dev/null
					mail -a /opt/backup.sql -s "Backup File" < /dev/null


Attachments are indicated by the -a suffix. For Debian-based systems that use the mailutils package, use -A. 

You might run into the following issue: Bash: mail: command not found We may also use comma-separated emails in order to send the email to several recipients at once.

					mail -s “Test Email”, < /dev/null

3. Using the Linux ‘mutt’ Command

Mutt is mostly used to read emails from local user mailboxes from a Linux terminal, but it can also be used to read emails from POP/IMAP servers. The mutt order is identical to the mail command. To send an email, use a few of the examples below.

					mutt -s "Test Email" < /dev/null

Send an email with a file attachment. 

					mutt -s “Test Email” -a /opt/backup.sql < /dev/null

4. Using the Linux ‘SSMTP’ Command

sSMTP allows users to send emails from a Linux command line to an SMTP server. Using the following command to send an email to the user Now, enter your email’s subject as seen below, using the keyword Subject. Then type the message you want to send to the recipient. To send the email, click CTRL+d (d) after you have finished your message.

Subject: Test SSMTP Email
Email send test using SSMTP
via SMTP server.


5. Using the Linux ‘telnet’ command

All system administrators, in my experience, use the telnet command to test remote port connectivity or log in to the server remotely. Most Linux newbies are unaware that we can also send email via telnet, which is a safer way to troubleshoot email sending issues.

Here’s an example of how to send an email using telnet. The user input is highlighted in red, and the remaining text represents the commands’ responses.

					telnet localhost smtp

Connected to localhost.localdomain (
Escape character is '^]'.
220 ESMTP Sendmail 8.13.8/8.13.8; Tue, 22 Oct 2013 05:05:59 -0400
250 Hello [], pleased to meet you
mail from:
250 2.1.0 Sender ok
rcpt to:
250 2.1.5 Recipient ok
354 Enter mail, end with "." on a line by itself
This is test email only

250 2.0.0 r9M95xgc014513 Message accepted for delivery
221 2.0.0 closing connection
Connection closed by foreign host.
With this list, we will be adding more ways in the near future. We also ask that you assist us with any additional commands that you are familiar with but are not listed above.
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit
Share on vk
Share on tumblr
Share on skype
Share on stumbleupon
Share on whatsapp
Share on email

Related posts

Leave a Reply

Required fields are marked *