[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->] |
The primary means of sending plain-text messages (or binaries in attachment files) between users across computer networks and systems on the Internet is called electronic mail, or email (and more often than not these days, just "mail").
The number of email applications (called mail user agents, or MUAs) available for Linux is large, and you could spend endless hours exploring the details of all of them. Instead of guiding you toward this route, this chapter attempts to do three things: give a brief intro to using the default mail agent; give an overview of other well-supported mail agents, with pointers on where to go for more info; and show how you can use other tools on the system to manipulate your email.
The mail
tool is the default mail agent on Debian and most other
Linux systems. It comes without many bells and whistles that are
standard with most MUAs, and any user who sends and receives email
more than occasionally will certainly want to learn a more advanced
system (see Picking the Right Mail Application).
However, mail
is available on almost all Unix-based systems, and
it works in a pinch -- by learning to use it you can always send and
receive email on any Linux- or Unix-based system you encounter.
NOTE: On some Unix-based systems, the name of the tool is
mailx
instead of mail
.
To send an email message with mail
, give the email addresses to
which you are sending as arguments, and then type the message proper in
the lines that follow; type C-d on a line by itself to signify the
end of the message body, and to send the message.
lisa@example.com
, type:
$ mail lisa@example.com [RET] Subject: Hello [RET] Hi there, long time no talk! I'm just learning how to use [RET] Linux and thought I'd show you how easy it is to send email! [RET] C-d Cc: [RET]
The text you type on the `Subject:' line is displayed as the
subject of your email message, and the lines of text you type after that
is the body text of the message. Type C-d on a line alone to end
the message. Then, mail
prompts for `Cc:' addresses; a
"carbon copy" of the email message is sent to any addresses you give
here, if any (just type [RET] for none, and separate multiple
addresses with commas).
When you type, mail
just reads the standard input like any other
command-line tool, so there's little direct editing capability in this
basic email service -- use C-u to erase the current line, and
C-c C-c (that is, C-c pressed twice) to cancel your input
and abort the message altogether.
That's it! No bells, no whistles -- but no time-wasting excess, either.
To send an email message to another user on the same system, give their username on the system instead of an email address (technically, you are giving the email address, since email addresses take the form of username@hostname; when hostname is omitted, the localhost is assumed).
mrs
on your local system, type:
$ mail mrs [RET] Subject: are you going to the party tonight? [RET] C-d Cc: [RET] Null message body; hope that's ok $
This command sends an email message to the user mrs
on the local
system. The email message itself is empty, but the subject is a short
note asking whether user mrs
will be attending a party.
NOTE: Besides being good for sending mail to users that you
might share your system with, mail
is useful for sending
yourself mail, as a way to give yourself a reminder at your
terminal (see Sending Yourself Email Reminders).
The mail
tool is also useful for mailing the contents of a text
file or the text output of a command. To do this, give the email
addresses you want to send to as arguments to mail
, and use the
standard input redirection operators to redirect the text to use as the
message body (see Redirecting Input and Output).
terrapin@example.com
, type:
$ mail terrapin@example.com < trades [RET]
A variation on the previous recipe is to use mail
and shell
redirection to send the output of some command to some address via
email. You can, for example, send the contents of a URL as an annotated
text file by redirecting the output of the lynx
Web browser
(see Reading Text from the Web).
droneon@example.com
, type:
$ mail droneon@example.com < lynx -dump -number_links http://etext.org/ [RET]
The following table lists the special keystrokes that work when
composing a mail
message, and describes their functions.
KEYSTROKE | DESCRIPTION |
C-c C-c |
Abort the current message and exit mail .
|
. [RET] or C-d |
On a blank line, either of these commands sends the message and
then exits mail .
|
C-u |
Erase the current line and move the cursor to the beginning of the line. |
COMMAND | DESCRIPTION |
~!command |
Run command in a shell. |
~baddress |
Send a blind carbon copy to the usernames or email addresses given. |
~d |
Copy the file `dead.letter' from your home directory into the message. |
~e |
Edit the message in the default text editor program. (When you exit
the text editor, you are returned to mail .)
|
~fnumber |
Insert copies of the specified received messages into the message body. Messages are specified by number or a range (for example, `2-4' inserts messages two through four inclusive); if no number is given, the current received message is inserted. |
~F |
Same as `~f', but reads in the messages with full headers. |
~rfile |
Insert a copy of the file file into the message. |
~wfile |
Write a copy of the body text into the file file. |
~f [RET] ~e [RET]
On Linux-based systems, the INBOX is a text file on the system
where your incoming mail is written to. Its location is always given by
$MAIL
, a special shell variable (see Changing the Shell Prompt).
$ echo $MAIL [RET]
Usually, the INBOX location is in the `/var/spool/mail' directory,
and has the same name as your username -- so if your username is
mrs
, your INBOX is likely `/var/spool/mail/mrs'.
You shouldn't directly edit this file, because doing so can inadvertently cause you to lose incoming mail.
To see if you have any mail waiting in your INBOX, type mail. If
you don't have any mail, mail
will indicate this and exit; if you
do have mail waiting, mail
outputs a list of message
headers, one line per message, each containing the status of the message
(`N' for new messages, blank for previously read messages), the
message number, the name of the sender, the date and time the message
was received, and the number of lines and characters in the message.
$ mail [RET] Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/m": 3 messages 3 new >N 1 mrs Mon Sep 6 17:29 13/345 "Re: A modest proposal" N 2 Ray Tue Sep 7 04:20 15/694 "Latest news" N 3 lisa@example Tue Sep 7 09:35 19/869 "Re: Hello" &
In this example, the user has three messages waiting -- one from
mrs, one from Ray, and one from lisa@example.com
.
The mail
prompt is an ampersand (`&') character; from there,
you can read, delete, reply to, and save messages.
When you type [RET] at the `&' prompt, mail
outputs the
next unread message to the screen. You can also type a number to output
that message.
mail
, type:
& [RET]
mail
, type:
& 3 [RET]
There are two ways to exit mail
: type q to exit mail
and apply the deletion commands you have given, if any, to your INBOX;
type x to exit mail
and revert the state of your INBOX to
how it was before you ran mail
.
mail
and revert your INBOX to its state before you
started mail
, type:
& x [RET]
To delete a message in mail
, type d at the `&' prompt
after reading the message in question. You can also specify a message or
a range of messages to delete as an option to d.
& d [RET]
& d3 [RET]
& d10-14 [RET]
The following table summarizes the most common mail
commands for
reading mail; these commands work at the `&' prompt.
COMMAND | DESCRIPTION |
? |
Output a help menu containing a list of mail options and their meanings. |
d |
Delete a message. Give the number or range of the message(s) to delete as an argument. |
h |
Output a list of headers of mail messages. You can specify a range or the number of the message to start with. |
q |
Exit mail and apply the changes you have made in this
mail session to your INBOX.
|
r |
Reply to the message you last read; you can also give a message number as an argument to reply to that message number. |
u |
Undelete a message you have deleted in the current mail session. Give the number or range of the message(s) to be undeleted as an argument. |
x |
Exit mail and revert the INBOX to its state before this
mail session.
|
s file |
Save the message you last read to the file in your home directory
specified by file (if the file does not exist, mail will
ask you whether or not it should create it).
|
mail
, and the other MUAs) to read this file in special ways, you
can also view this file like any other text file (see Viewing Text).
A mail folder is simply a text file whose contents consist of saved mail messages; any tool that works on text can be used on a mail folder.
The following subsections describe some of the common ways to manage and otherwise modify your saved mail.
Debian: `elm-me+' WWW: http://www.instinct.org/elm/
You can view your mail folders in less
or edit them in a text
editor, although the folder will appear as one long scroll containing
all of the messages the folder contains.
You can also view them in elm
(see Picking the Right Mail Application) or open them with mail
, and they will
appear in the normal way as your INBOX would appear with these tools.
To view a mail folder with elm
, give the name of the folder as
an argument to the `-f' option.
elm
, type:
$ elm -f ~/email/mrs [RET]
If you save your mail messages in a lot of separate folders, you can
view a sorted list of all messages from all files by using cat
in
conjunction with elm
. Concatenate all the folders into one with
cat
and then view that file in elm
as you would view any
folder.
$ cat ~/email/* > allmessages [RET] $ elm -f allmessages [RET]
These commands write a new file, `allmessages', in the current
directory, containing the contents of all email folders in
`~/email'; then, that file is viewed in elm
.
NOTE: To view a list showing who all the messages in a folder
are from, use frm
; see Seeing Who Your Mail Is From.
Debian: `biff' WWW: ftp://ftp.uk.linux.org/pub/linux/Networking/ WWW: http://www.splode.com/~friedman/software/packages/index.html
The biff
tool notifies you when new mail arrives, by printing the
header and first few lines of a mail message.
To turn biff
on, use `y' as an option. To turn biff
off, so that you stop being notified when new mail arrives, use `n'
as an option. biff
options don't take a hyphen.
biff
on, type:
$ biff y [RET]
Some people put the above line in their `.bashrc' file so that
biff
is always set on in all of their shells (see Changing the Shell Prompt).
Typing biff
alone with no options will tell you whether
biff
is set to `y' or `n'.
biff
is set to, type:
$ biff [RET]
A companion tool, xbiff
, works only in the X Window System (you
can use the regular biff
in X, too). When you start it,
xbiff
draws a window containing a mailbox that looks like
this:(38)
When you have mail, xbiff
rings the system bell, the window icon
reverses color, and the mailbox flag goes up:
NOTE: The original version of biff
was named after a
dog. In the early 1980s at a UC Berkeley computer lab, a girl would
bring her dog, Biff, with her when she went to use the computers. Biff
was known for barking at the mailman when he came in to deliver the
day's mail. He was also very popular with all of the BSD UNIX hackers at
Berkeley, and when one of them wrote a mail notification tool, he
thought of Biff -- hence the name. (Biff, the dog, died in August 1993.)
Debian: `elm-me+' WWW: ftp://ftp.uu.net/networking/mail/elm
Use messages
to count the number of mail messages in a folder
or file. Give the name of a mail folder as an argument; with no
arguments, it counts the mail you have waiting in your INBOX.
$ messages [RET]
$ messages ~/email/saved [RET]
Debian: `elm-me+' WWW: ftp://ftp.uu.net/networking/mail/elm
Use frm
to output a list of sender names and subjects for your
mail. Give the name of a mail folder as an option; with no options,
frm
reads your INBOX.
$ frm [RET]
$ frm ~/email/saved [RET]
NOTE: An alternate tool, from
, works in similar fashion,
but it does not output subject lines; instead, it outputs the names of
senders and the time that messages were received.
Debian: `vrfy' WWW: ftp://ftp.nikhef.nl/pub/network/
Use vrfy
to determine whether or not a given email address
works. This is useful when you are unsure whether or not you have the
right email address for someone. If the address works, vrfy
outputs a message indicating that the recipient exists; if the address
is not valid, vrfy
outputs a message saying that the user is
unknown.
user@example.edu
is valid,
type:
$ vrfy user@example.edu [RET]
Use the `-f' option to specify a text file containing email
addresses; vrfy
attempts to verify all email addresses contained
in the file.
$ vrfy -f net-legends-faq [RET]
NOTE: vrfy
relies on the remote system to get this
information; in these days of the heavily corporatized Internet, an
increasing number of sites no longer supply this kind of information to
the general public. However, it's still useful enough to be worth
mentioning.
Debian: `metamail' WWW: http://bmrc.berkeley.edu/~trey/emacs/metamail.html
MIME ("Multipurpose Internet Mail Extensions") is an Internet standard
for encoding and attaching files to mail messages. It's used when
sending image, audio, or other non-plain-text data via email.
Normally, you read and send MIME mail with your MUA. The following
recipes, which show ways to send and receive MIME mail on the command
line, are useful for when you just use the mail
tool to read and
send occasional mail with an attachment, but the built-in methods for
manipulating MIME mail in any reasonable MUA will invariably be easier
and more convenient than the techniques described here (see Picking the Right Mail Application).
To read a mail attachment, write the message to a file and then run
metamail
with the file name as an argument. metamail
lists
each attachment and prompts you about whether it should display the
attachment, write it to a file, or skip it.
$ mail [RET] Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/m": 1 messages 1 new >N 1 Photo Dept. Mon Feb 12 14:37 231/10980 "New Images" & w1 image.mail [RET] "image.mail" [New file] & x [RET] $ metamail image.mail [RET]
In this example, the mail
tool was used to open the INBOX and
write the message to a file called `image.mail'; then,
metamail
was run with the file name as an argument.
To send a file as an email attachment, use metasend
. It prompts
for the values to use in the `To:', `Subject:', and `CC:'
header fields, plus the following values for each MIME attachment: its
`Content-type:' field, which describes the kind of data the
attachment contains; the file name; and the type of encoding to use, if
any (usually one is recommended).
dali@example.org
, type:
$ metasend [RET] To: dali@example.org [RET] Subject: The image you requested [RET] CC: [RET] Content-type: image/jpeg [RET] Name of file containing image/gif data: dream.jpeg [RET] Do you want to encode this data for sending through the mail? 1 -- No, it is already in 7 bit ASCII 2 -- Yes, encode in base64 (most efficient) 3 -- Yes, encode in quoted-printable (less efficient, more readable) 4 -- Yes, encode it using uuencode (not standard, being phased out) 2 [RET] Do you want to include another file too (y/n) [n] ? n [RET] Delivering mail, please wait... Mail delivery apparently succeeded. $
The following table lists values to use in the MIME `Content-type:' field for various kinds of files.
VALUE | FILE TYPE |
application/gzip |
File compressed with gzip .
|
application/zip |
File compressed with zip .
|
application/postscript |
PostScript file. |
image/jpeg |
JPEG image file. |
image/png |
PNG image file. |
audio/basic |
Audio file. |
audio/mpeg3 |
MP3 audio file. |
audio/wav |
WAV audio file. |
Debian: `sigrot' WWW: ftp://metalab.unc.edu/pub/Linux/system/mail/misc/
A signature file (often called a "dot sig," and written as
`.sig') is a text file containing text that you want to appear at
the end of email messages and other online postings.
Sometimes, people put their name, email address, and a small quote, or a
piece of ASCII art (such as text written in a figlet
font---see Horizontal Text Fonts); once the World Wide Web
became popular, many people started including the URL of their home page
in their `.sig'.
The use of signatures goes in and out of vogue with the years; you can decide whether or not you want to use one, but whatever you do, be sure to keep your `.sig' at most four lines in length -- to use any more is considered very bad form. A first line consisting only of `-- ' is sometimes used; many applications recognize this text as the beginning of a `.sig' when processing messages.
You create your signature file in a text editor, just like any other text file. Name the file `.signature' or `.sig', and keep it in your home directory.
If you want to use more than one signature, use sigrot
to
"rotate" your various signatures -- every time you run sigrot
,
it selects one of the signature files you keep in your `.sigrot'
directory and writes it to `.signature'. To change your
`.signature' every time you log in, you would run sigrot
in
your `.bash_login' file (see The Shell).
The following table lists some of the more popular MUAs that are available for Linux, describing their special features, and listing their Debian package name and URL (when available).
APPLICATION | DESCRIPTION |
balsa |
A graphical email client that works in X with GNOME installed; its
interface is inspired somewhat by the proprietary Eudora.
Debian: `balsa' WWW: http://www.balsa.net/ |
elm |
A menu-driven MUA, elm was popular in the early 1990s among
experienced users -- it has some interesting features, including ways to
send mails in batch mode to many addresses at once, and a tool to send
telephone messages as email messages. Interest in elm has waned
somewhat over the years, and most novices are advised to try mutt
instead.
Debian: `elm me+' WWW: http://www.instinct.org/elm/ |
gnus |
The gnus newsreader for Emacs(39) can also be used to read and send mail. It
has many features and should appeal to Emacs lovers -- but a warning: it
can be daunting to learn!
Debian: `gnus' WWW: http://www.gnus.org/ |
mew |
mew is an Emacs mail and news facility developed in
Japan. It shows promise as a fairly new MUA and has many features for
handling mail in complex ways.
Debian: `mew' WWW: http://www.mew.org/ |
mh-e |
MH-E is an Emacs front end to nmh , below. It's very
powerful, yet it remains easy to use.
Debian: `emacsen-common' WWW: http://www.emacs.org/ |
mozilla |
Netscape Inc.'s open source Web browser, mozilla , has its
familiar and self-explanatory email interface that works in the X Window
System.
Debian: `mozilla' WWW: http://www.mozilla.org/ |
mutt |
The MUA currently in favor among many vi users is
mutt ; it is one of the most popular MUAs for Linux.
Debian: `mutt' WWW: http://www.mutt.org/ |
nmh |
The Rand "Mail Handling" system, mh , is not one
application but a collection of small tools for manipulating mail
folders. It should appeal to those who excel at building complex
commands from combinations of simple tools and operators. nmh is
the new "Mail Handling" system, containing rewrites and
improved versions of the mh tools. Most Linux systems will
install this over the old mh .
Debian: `nmh' WWW: http://www.mhost.com/nmh/ |
vm |
VM ("View Mail") is a facility for reading and sending mail in
Emacs. Older than gnus and mew , it is very configurable.
Debian: `vm' WWW: http://www.wonderworks.com/vm/ |
wl |
Wanderlust is a MUA for Emacs designed to facilitate reading your
mail on multiple computers.
Debian: `wl' WWW: http://www.gohome.org/wl/ |
[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]