5 Easy Ways to Send An email from the Linux Command Line [ Ultimate Guide ]
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 firstname.lastname@example.org < /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" email@example.com < /dev/null
mail -a /opt/backup.sql -s "Backup File" firstname.lastname@example.org < /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” email@example.com,firstname.lastname@example.org < /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" email@example.com < /dev/null
Send an email with a file attachment.
mutt -s “Test Email” -a /opt/backup.sql firstname.lastname@example.org < /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 email@example.com. 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.
ssmtp firstname.lastname@example.org Subject: Test SSMTP Email Email send test using SSMTP via SMTP server. ^d
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 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 fbreveal.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 22 Oct 2013 05:05:59 -0400 HELO yahoo.com 250 tecadmin.net Hello tecadmin.net [127.0.0.1], pleased to meet you mail from: email@example.com 250 2.1.0 firstname.lastname@example.org... Sender ok rcpt to: email@example.com 250 2.1.5 firstname.lastname@example.org... Recipient ok data 354 Enter mail, end with "." on a line by itself Hey This is test email only Thanks . 250 2.0.0 r9M95xgc014513 Message accepted for delivery quit 221 2.0.0 fbreveal.com closing connection Connection closed by foreign host.
How to use Registry Editor to navigate to any Registry key with a single click
You might get tired of manually navigating to various registry keys if you find yourself fiddling with Registry Editor and…