Q. Hey vivek, I need to know how to read and send mail from command line. I’m using Debian Linux. Also can you tell me how do I print names of those who have sent mail?
A. Sending and receiving mail from command line is quite command under UNIX or Linux operating system. You need to use following commands:
a) mail: send and receive mail
b) from: print names of those who have sent mail
c) mutt: Mutt is a small but very powerful text based program for reading electronic mail under UNIX operating systems, including support color terminals, MIME, and a threaded sorting mode.
d) pine: Yet another text based program for reading electronic mail under UNIX operating systems. Originally written for inexperienced users, Pine's basic features are generally very easy to use.
Task: Check for mail / print names of those who have sent mail
The from utility prints out the mail header lines from the invoker’s mailbox.
$ from
Task: Read mail
Mail is an intelligent mail processing system:
$ mail
In normal usage mail is given no arguments and checks your mail out of the post office, then prints out a one line header of each message found. The current message is initially the first message (numbered 1) and can be printed using the print command (which can be abbreviated ‘p’). You can move among the messages much as you move between lines in ed, with the commands ‘+’ and ‘-’ moving backwards and forwards, and simple numbers.
After examining a message you can delete message by typing d
You can reply message by typing r
The message can be undeleted u by giving its number, or the mail session can be aborted by giving the exit x command.
Task: Compose mail
Use following format:
mail -s <subject> <mailaddress>
For example write mail to boss@yahoo.com:
$ mail - "Hello" boss@yahoo.com
You are then expected to type in your message, followed by an ‘control-D’ at the beginning of a
line. To stop simply type dot (.):
Output:
Hi,
This is a test
.
Cc: Task: Mail a whole text file
Mail a whole text file called demo.txt to boss@yahoo.com:
$mail -s "Report 05/06/07" boss@yahoo.com < demo.txt
You can also type mutt or pine to read and send mail:
$ mutt
OR
$ pine
See also:
Howto send mail with attachment
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 26 comments… read them below or add one }
i got an acer aspire one for crimbo.
it has msn on it but i cant seem 2 get it 2 work even though i already have an account on windows msn. do i have 2 have a certain email network because everytime i try to log in it says “our protocol is not supported by the server”
please help me.
Hey Vivek,
Do you know how can we change the from email address while using the mail command to send emails?
You can’t.
But, you can write a perl or python script. There is also a utility called ssmtp or sendmail -ba option.
HTH
Yeah I know that option, but I am using postfix. So the other option I see if using content filtering in postfix to change the from email address to certain domains. Any ideas about this filter setup?
hey Vivek,
I got the resolution.
The following is the syntax which will do the job:
mail -s "subject" recipient@domain.tld -- -f sender@domain.tldGagan,
Thanks for sharing back the resolution.
Thank you so much….
thanks,
Raja K
Thanks Gagan. The command you provided helped me as well.
Hi,
I have used but it is taking long time.
My OS is Red hat 4.
Hi,
I started Sendmail.
And then I wanted to send an email with the mail command to my Hotmail-account.
But it doesn’t work.
My mail always end up in the file /var/spool/mail/root, namely:
————————————————————————————————————
Final-Recipient: RFC822; cccc@hotmail.com
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We generally do not accept email from dynamic IP’s as they are not typically used to deliver unauthenticated SMTP e-mail to an Internet mail server. http://www.spamhaus.org maintains lists of dynamic and residential IP addresses. If you are not an email/network admin please contact your E-mail/Internet Service Provider for help. Email/network admins, please visit http://postmaster.live.com for email delivery information and support
Last-Attempt-Date: Thu, 13 Aug 2009 18:45:32 +0200
–n7DGjWx4027730.1250181932/localhost.localdomain
Content-Type: message/rfc822
Return-Path:
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.8/8.13.8) with ESMTP id n7DGjVx4027728
for ; Thu, 13 Aug 2009 18:45:31 +0200
Received: (from root@localhost)
by localhost.localdomain (8.13.8/8.13.8/Submit) id n7DGjU2o027727
for cccc@hotmail.com; Thu, 13 Aug 2009 18:45:30 +0200
Date: Thu, 13 Aug 2009 18:45:30 +0200
From: root
Message-Id:
To: ccccc@hotmail.com
d
–n7DGjWx4027730.1250181932/localhost.localdomain–
——————————————————————————————————————
Do you maybe know what the reason is?
Thanks in advance !!
Greetings
Problem is the hostname set for your machine. It seems that you haven’t changed the hostname for your machine. It still shows localhost.localdomain. Many mail servers around do not accept emails originating from localhost.localdomain. The hostname should be a FQDN if you to send emails over the internet.
Can somebody teach me how to configure mail using solaris 9.
This is an automatically generated Delivery Status Notification.
Delivery to the following recipients failed.
rd.shiva@hotmail.com
Final-Recipient: rfc822;rd.shiva@hotmail.com
Action: failed
Status: 5.0.0
Diagnostic-Code: smtp;550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We generally do not accept email from dynamic IP’s as they are not typically used to deliver unauthenticated SMTP e-mail to an Internet mail server. http://www.spamhaus.org maintains lists of dynamic and residential IP addresses. If you are not an email/network admin please contact your E-mail/Internet Service Provider for help. Email/network admins, please visit http://postmaster.live.com for email delivery information and support
Please anybody help me…. urgent….
Thanks
Cris J
is that possible to send a txt file which includes colored text as it it?
When i am trying to send the txt file, the recipient receives the file with default color text but originally file contains text with red and blue color.
I am trying to send via a command line
Hello Sir/Madam,
I need basic and full detail about solarise administrator.can you please send me.
I am waiting for your favorable reply.
Hi, Can anyone tell me or suggest me as what should be my move if I want that a procedure which I run in UNIX is; if accidently or intentionally killed then it should shoot a mail to my mail ID as to inform that the process has been terminated.
I want to know that what has to be done and studied to create such procedure and knowledge of what is required???
Thanks for helping me in advance
How can you find out if you have the permission to send a message?
We are not here to solve ur TCS tutorials. What is your DT ID, Password Sampath, I’ll complete your tute myself?
To check the file permissions, we can give the command;
% ls -l
If, in the output, we get; -rw——- , then only the owner have the right to send the message, while others can’t.
1. Create a tree structure named ‘training’ in which there are 3 subdirectories – ‘level 1’,’ level2’ and ‘cep’. Each one is again further divided into 3. The ‘level 1’ is divided into ‘sdp’, ‘re’ and ‘se’. From the subdirectory ‘se’ how can one reach the home directory in one step and also how to navigate to the subdirectory ‘sdp’ in one step? Give the commands, which do the above actions?
2. How will you copy a directory structure dir1 to dir2 ? (with all the subdirectories)
3. How can you find out if you have the permission to send a message?
4. Find the space occupied ( in Bytes) by the /home directory including all its subdirectories.
5. What is the command for printing the current time in 24-hour format?
6. What is the command for printing the year, month, and date with a horizontal tab between the fields?
7. Create the following files: chapa, chapb, chapc, chapd, chape, chapA, chapB, chapC, chapD, chapE, chap01, chap02, chap03, chap04, chap05, chap11, chap12, chap13, chap14, and chap15.
8. With reference to question 7, What is the command for listing all files ending in small letters?
9. With reference to question 7, What is the command for listing all files ending in capitals?
10. With reference to question 7, What is the command for listing all files whose last but one character is 0?
11. With reference to question 7, What is the command for listing all files which end in small letters but not ‘a’ and ‘c’?
12. In an organisation one wants to know how many programmers are there. The employee data is stored in a file called ‘personnel’ with one record per employee. Every record has field for designation. How can grep be used for this purpose?
13. In the organisation mentioned in question 12 how can sed be used to print only the records of all employees who are programmers.
14. In the organisation mentioned in question 12 how can sed be used to change the designation ‘programmer’ to ‘software professional’ every where in the ‘personnel’ file
15. Find out about the sleep command and start five jobs in the background, each one sleeping for 10 minutes.
16. How do you get the status of all the processes running on the system? i.e. using what option?
You can use this line:
echo ‘This is my message’ | mail -s ‘This is the subject’ lucho@server.com.uy
regards!
Hi,
I want to send the output of mail.txt to my mail id but i am getting the following output.
[@****** ~/Scripts]$ cat mail.txt | mail -s “BAU Monitoring” Ramandeep.Garg@***.com
[@***** ~/Scripts]$
I got the prompt back but did not receive any mail.
* Email id is correct.
* I ran this command in putty in UNIX.
Can you please help me out and send your understanding to ramandeep_garg@infosys.com
Thanks in advance
Please, check your log file (ex: exim4)
Ex:
PS: You can paste here a link to your log file (use pastebin)
Hi,
Is there any way we can send high priority email using mail.
mail -s “TEST” “to@xyz.com” — -r “from@xyz.com”
Do you know what parameter to add high prioruty email for above command.
Thanks.
Hi,
Thanks alot for your great script but i have two questions :
1. Now if there is more than one mount point exceeding 90% it will send an email for each mount point, i need one email contain all moint point exceeding 90%.
2. How to send mount point name instead of filesystme name?
Thank your very much
Muhanad
I use Alpine to send and recive mail.
I send mail to gmail and it is work.
I send from gmail to my local server and it not get to me (no error in gmail).
I send from my local server to it selfe :
The mail found in send mails but not recived to inbox.