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
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 18 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
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?