If I ask you how to send an email, what would you say? You will say go to gmail or yahoo mail and send the email. But, do you know that you can send emails using your Linux command line? Yes! you heard me right.

We can do this by using the mail command. In other words, it is a simple email client that gives you the basic email facilities. Moreover, this will allow you to send and read emails in your inbox. In this guide, I will show you how to do that.

Step 01 : Installation

Firstly, you have install it by using the following command

#sudo apt install mailutils

installing mailutils

Step 02: Sending a simple mail

Run the following command to send a simple mail. Moreover, you can set the subject of the mail and the receiver’s address in the command

#mail -s “<subject>” <Email_address>

send email

Once you hit enter, you will be asked to add the CC address and type in the message. After that, the mail command would send the message.

Step 03 : Setting the message body

You can also set the message body in just one line of command

#mail -s “<subject>” <Email_address> <<< <message>

message body

Step 04 : Get the input from a file

Similarly, you can direct the mail command to get the message from a file

#mail -s “<subject>” <Email_address> < <location>

getting input from a file

Step 05 : Specify CC and BCC recipients

Use the below command to Specify CC and BCC recipients in one line of command

#mail -s “<subject>” <Email_address> -c <CC_address> -b <BCC_address>

specify cc and bcc

Step 06 : Send to a local user

You can also send a mail to a local system user

#mail -s “<subject>” <username>

send to local user

You could also append “@hostname” to the username. Therefore, the hostname should be the hostname of the current system.

#mail -s “<subject>” <username@hostname>

send to username

Step 07 : View a detailed output

If you need to view a detailed output, use the -v option

#mail -v -s “<subject>” <Email_address>

view verbose output

Step 08 : Check your inbox

You can also view your inbox.  For that, you simply have to run the mail command.


check inbox

In conclusion, mail command is a useful tool that we can use to handle our emails. Therefore, you can practice using this if you need to get rid of using the email clients when using the command line. Moreover, you can check this article to see another tool that you can use for this task.


The following two tabs change content below.
Ruwantha Nissanka is a Professional Cyber Security Engineer from Sri lanka with having a demonstrated history of providing cyber security services for multiple organizations in Sri Lanka. He is a positive person who wants to believe the best in others and he likes to help, encourage people and make them feel good.