5 ways to send emails using the command-line in Linux

Did you master using the command-line in Linux? There is no limit to what one can do via the Linux Terminal. One of such things we are going to discuss today are methods of sending an email using the command-line.

Once you become used to the marvelous Linux Terminal, you practically now want to do everything there in the Linux style. In this tutorial, we are going to show you how you can send an email from the Terminal and even include file attachments.

We are all used to the web interfaces and applications like Thunderbird Mail in Ubuntu which provide us with fantastic Graphical User Interfaces (GUI) to send our emails. Here, we will show you how to send emails technically from the console.

Sending an email using command-line

Sending mails from the Terminal is mainly useful when we need to write scripts that create emails and send them automatically. It also helps when we need to create cron jobs to manage bulk mails.

There are several command-line mail clients that we will use. Below are some which we will use for this tutorial. We will also show you how you install them.

  • Sendmail
  • Mail
  • Mutt
  • Mpack

It’s also good that you understand some of the options that we will use with the mail clients above.

  • s -represents the subject of the mail
  • a -used to denote the file attachment to send along with the email
  • c -Stands for Copy Email Address (CC)
  • b -Stands for Blind Copy email address (BCC)

Let’s look at five ways in which you can send an email to a recipient from the Linux Terminal.

1. Sendmail

Sendmail is one of the popular SMTP servers present in most Linux systems used to send emails from the command line. It does not come installed as a default utility in all systems. However, you can easily install it with the package manager.

Install Sendmail on RHEL/CentOS:

sudo yum install sendmail

On Ubuntu/Debian distributions:

sudo apt-get install sendmail

On Fedora:

sudo dnf install sendmail

Install sendmail
Install Sendmail

Using Sendmail

Sending emails using Sendmail utility is a straightforward process.

Step 1) Create a text file with the email content. Remember to include the subject, as indicated below.

cat sampleemail.txt

Subject: Send an email with SENDMAIL
Hello world
That is the sendmail utility

sendmail email contents
Sendmail email contents

Step 2) Use the Sendmail utility to send the mail using by executing the command below.

sendmail user@example.com < sampleemail.txt

2. Mail

We can also send emails from the Linux Terminal using the Mail command. First, let’s look at how you install this utility in different Linux distributions.

Install Mail on Ubuntu/Debian distributions:

sudo apt-get install mailutils


sudo yum install mailx

On Fedora:

sudo dnf install mailx

Install mailutils in Ubuntu/Debian
Install mailutils in Ubuntu/Debian

Using mail

The following command will send an email without an attachment.

echo "Hello World" | mail -s "Send an email with MAIL" usera@example.com

To send an email with a file attachment, use the command below.

echo "Hello World" | mail -a image1.img -s "Design Assignment" daygeek@gmail.com

Note, as described above, option -s represents the email subject and -a represents file attachments.

3. Mutt

Mutt is a powerful Linux command used to send emails using the Terminal. It works by reading mails from local user mailboxes and POP/IMAP servers. It also supports color Terminals, threaded sorting mode, MIME, and OpenPGP.

Install Mutt on Ubuntu/Debian distributions:

sudo apt-get install mutt


sudo yum install mutt

On Fedora

sudo dnf install mutt

Install mutt in Ubuntu
Install mutt in Ubuntu

Using Mutt

Sending an email with the mutt command is a straightforward process. You can also send a blank mail with mutt by adding < /dev/null right after the destination mail address.

mutt -s "Hello world" user@example.com < /dev/null


SSMTP enables you to send email from a local computer to a configured mailhost/mail hub.

Install SSMTP on Ubuntu/Debian distributions:

sudo apt-get install ssmtp


sudo yum install ssmtp

On Fedora:

sudo dnf install ssmtp

Install ssmtp in Ubuntu
Install ssmtp in Ubuntu


Use the command below to create the email you want to send.

echo -e "Subject: Email Subject\nHELLO WORLD" > /tmp/ssmtp-sampleMail.txt

To send the email, run the command below.

ssmtp user@example.com < /tmp/ssmtp-sampleMail.txt

5. Mpack

Mpack is also another commonly used command to send emails from the Terminal. It works by encoding the emails and attachments into one or more Multipurpose Internet Mail Extensions (MIME) before sending them to the required destination. Mpack also does not come pre-installed in most systems; however, you can install it from the package manager.

Install mpack on Ubuntu/Debian distributions:

sudo apt-get install mpack


sudo yum install mpack

On Fedora

sudo dnf install mpack

Install Mpack in Ubuntu
Install Mpack in Ubuntu

Using mpack

Execute the command below to send an email without an attachment.

echo "HELLO WORLD" | mpack -s "Testing Mpack" user@example.com

If you wish to send a file attachment along with the email, use the syntax in the command below.

echo "This is the mail body" | mpack -s "Subject" daygeek@gmail.com -a test1.txt


Those are five ways you can use to send emails from the Linux Terminal. Feel free to share information about other useful utilities you have used using the comment section below. Also, you can share your experience working with the commands we discussed in this tutorial. If you find this post resourceful, feel free to share the link with your friends.

Arun Kumar
Arun did his bachelor in computer engineering and loves enjoying his spare time writing for FOSS Linux. He uses Fedora as the daily driver and loves tinkering with interesting distros on VirtualBox. He works during the day and reads anything tech at night. Apart from blogging, he loves swimming and playing tennis.


Please enter your comment!
Please enter your name here




Basics of Working with the SQLite Database in Python

A database is one of the most useful and popular files for storing data; they can be used to store any kind of data, including text, numbers, images, binary data, files, etc. SQLite is a relational database management system based on the SQL language. It is a C library, and it provides an API to work with other programming languages, including Python. It does not require a separate server process to be run as needed in large database engines like MySQL and Postgresql.

5 Ways to Check the Linux Version

When most people talk of Linux, they are always referring to a Linux distribution. However, this is not the case. Linux itself is a kernel which acts as a bridge between user applications and the hardware. When we talk of a Linux distribution, we refer to an operating system developed from the Linux kernel. A distribution comes with a package manager, pre-installed applications, a Desktop Environment, and several more features.

Getting Started with Linux Operating System

The Linux operating system brings forth a vibrant mix of features and security, making it the best alternative to macOS or Windows operating systems. In this post, we will give you a master guide on Getting started with Linux systems - taking you from a complete beginner to a level where you can begin testing the various Linux distributions available with much ease.

How to Create a Comprehensive Mail Server on Ubuntu

Postal is a free and open-source mail server used to send and receive emails. It comes loaded with tons of excellent features and functionalities, making it extremely popular among large organizations as well as in enterprise settings.

The 10 Best Linux Performance Monitoring Tools

Do you want to monitor the performance of your Linux system? Are you looking for some powerful performance monitoring tools to help you out? If you agree, it's your day as we have put together a detailed list of the ten best Linux performance monitoring tools.

How to Boot your Windows or Linux PC from a USB Drive

Sometime back, the process of installing an operating system required users to pop a bootable media disk into their DVD or CD drive and use it to boot the PC. But times have changed. Nowadays, the most common way of installing an OS is booting from a USB drive. The use of USB drives is further propelled by the current production of slim and lightweight laptops with no support for DVD/CD drives.


Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

Manjaro ‘Gellivara’ XFCE Edition (17.0.5) in 10 Screenshots

Want to take a quick virtual tour Manjaro XFCE edition instead of downloading GBs worth of ISO image and then making a Live USB of it? We will make it easy for you. Here are a series of screenshots of the important aspects of Manjaro Linux in XFCE edition. This is a light-weight edition, and aims to be fast and low on system resources. You will be amazed on how it is still visually appealing and user friendly.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

All about Ubuntu editions and which version should you use?

Ubuntu is one of the most popular Linux distributions developed and released by Canonical, and not without reason. It has very enriched repositories, with support for all the programs you could ever need.

The 6 Best Linux File Recovery Software

Now and then, most of us lose important data in our computers either through accidental deletion, virus attacks, permanent removal of files, etc. Some of these files contain critical information that cannot be assumed and needs recovery. In this post, we will discuss some of the best data recovery available for Linux systems. The fantastic part is that most of them are opensource and freely available for use.