How to send mail from terminal using mail command

Yesterday (11-Mar-2014) my friend migrated his server from one DC to another DC and he faced some mail problem and can’t able to resolved it himself. He requested me to look into the issue. I found out the root causes of issues and resolved it. That time, i don’t have test email id to check whether the issue resolved or not and i remember the mail command and send the test mail.

1) What is mail command ?

Mail is an intelligent mail processing system which you can send mail from command line.

2) How to use mail command to send mail from terminal ?

Use the mail command with below format and send the mail from terminal. After typed your subject press Ctrl+D you will be popup to enter cc email id, if needed type it or else, hit enter.

[email protected] [/etc]# mail [email protected]
Subject: Tested by Magesh M
This is TEST mail tested by Magesh M
Cc:
[email protected] [~]#

Output:

Now, i’m going to check my gmail inbox whether the mail are received or not. And found that its received. The details are below.

from: root [email protected]
to: [email protected]
date: Wed, Mar 12, 2014 at 5:51 PM
subject: Tested by Magesh M
mailed-by:	 server.2daygeek.co.in
Mail body : This is TEST mail tested by Magesh M

3) How to use mail command to send mail from terminal with echo ?

Use the mail & echo command with below format and send the mail from terminal.

[email protected] [~]# echo "This is test mail by Magesh M" | mail -s Test [email protected]

Output:

Now, i’m going to check my gmail inbox whether the mail are received or not. And found that its received. The details are below.

from: root [email protected]
to:	[email protected]
date: Wed, Mar 12, 2014 at 6:15 PM
subject: Test
mailed-by: server.2daygeek.co.in
Mail body : This is test mail by Magesh M

Details :

  • Command : echo
  • Body : This is test mail by Magesh M
  • Command : mail
  • Subject : Test
  • Destination mail id : [email protected]

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...