Send Email from Linux Terminal

1. Using ‘sendmail’ Command
Sendmail is a most popular SMTP server used in most of Linux/Unix distribution. Sendmail allows sending email from command line. Use below instructions to send email using ‘sendmail‘ command. Create a file using following content.

[root@tecadmin ~]# nano /tmp/email.txt
Subject: Terminal Email Send
Email Content line 1
Email Content line 2

Subject: line will be used as subject for email. Now send email using the following command.

[root@tecadmin ~]# sendmail < /tmp/email.txt

2. Using ‘mail’ Command
mail command is most popular command to send emails from Linux terminal. Use few of below examples to send an email.

If mail command is not installed, you can install it by:

(for Debian/Ubuntu System) or

apt-get install mail-utils

(for Redhat based system)

yum install mailx
[root@tecadmin ~]# mail -s "Test Subject" < /dev/null

-s is used for defining subject for email. Also, you can send the email with an attachment.

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

-a is used for attachments

Also, we can add comma separated emails to send the email to multiple recipients together.

# mail -s "Test Email", < /dev/null

3. Using ‘mutt’ command
Mutt is basically used for reading mails from Linux terminal from local user mail boxes, also useful to read emails from POP/IMAP servers. Mutt command is little similar to mail command. Use few of below examples to send email.

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

Send email including attachment

# mutt -s "Test Email" -a /opt/backup.sql < /dev/null

4. Using ‘SSMTP’ Command
sSMTP allows users to send emails from SMTP server from Linux command line. For example to send an email to user use following command. Now type your subject of the email as below with keyword Subject. After that type your message to be sent to the user, After finishing your message press CTRL+d (^d) to send the email.

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

5. Using ‘telnet’ Command
As my experience all system administrators use telnet command to test remote port connectivity test or login to server remotely. Most of newbie in Linux doesn’t know that we can send email using telnet also, which is better way to trouble shoot email sending problems. Below is an example of email sending.

# 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.