CentOS Debian Mint openSUSE Red Hat Ubuntu

mail Command in Linux

mail Command in Linux

Introduction

Mail is the easiest way to send messages to your friends, partners. There are many ways to allow users to send emails, and you may not know it, Linux can also help you send emails using the mail command on the terminal. You can write the subject, content with the email address and send it by mail command.

This command is built-in on Linux distributions. Now we will start introducing you to using the mail command in Linux. Hope you understand.

Installing the mail package

Run the apt command to install the mailutils package:

$ sudo apt install mailutils

Output:

Then run:

$ sudo apt install postfix

Output:

Using the mail command

The syntax of the mail command:

$ mail -s "subject" [recipient's email]

[Type the message]

[Press Ctrl + D]

CC [You can skip by pressing Enter]

To understand clearly, we will try to send a mail to address “ubuntu@linuxer”:

$ mail -s "test" ubuntu@linuxer

Another way, you can send mail by single command:

$ mail -s "test" ubuntu@linuxer <<< 'Test'

If you want to attach the text file:

$ mail -s "test" ubuntu@linuxer <<< 'Hello, I want to share a file for you' /home/ubuntu/test/test1.txt

You can check the mail by command:

$ mail

Output:

To read the email, enter the email’s sequence number and press Enter. For example, I want to read the 3rd email:

To delete the email:

& d [email's sequence number]

For example:

Conclusion

We introduced you to how to use the mail command in Linux.

Thank you for reading!

Similar Posts