About Linux FAQ

Browse More FAQs:

Advertisements

Linux and UNIX Mail Command to send and receive mail

Posted by Vivek Gite [Last updated: April 22, 2007]

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

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.