Section 3.38. Electronic Mail: mail


[Page 99]

3.38. Electronic Mail: mail

It is useful to know how to use the Linux electronic mail facility from the very beginning, as it's a convenient way to ask your systems administrator or other seasoned users questions about Linux. The command-line interface is mail.

mail has a large number of features, so in accordance with the initial aim of this book, I shall only describe what I consider to be the most useful; consult man for more information. Figure 3-75 gives a description of mail.

Figure 3-75. Description of the mail command.

Utility: mail [-f fileName] { userId ]*

mail allows you to send and read mail. If a list of usernames is supplied, mail reads standard input, mails it to the specified users, and then terminates. Usernames can be a combination of the following forms:

  • a local user name (i.e., login name)

  • an Internet address of the form name@hostname.domain

  • a filename

  • a mail group

If no usernames are specified, mail assumes that you wish to read mail from a mail folder. The folder "/var/spool/mail/<username>" is read by default, where <username> is your own username, although this may be overridden by using the -f option. mail prompts you with an & and then awaits commands. A list of the most useful command-mode options is contained in the next few pages.

When mail is invoked, it begins by reading the contents of the mail startup file, which may contain statements that customize the mail utility. By default, mail reads the file ".mailrc" in your home directory, although the name of this file may be overridden by setting the environment variable MAILRC. Environment variables are discussed in Chapter 5, "The Linux Shells."

There are a large number of customizable options. The most important option is the ability to define mail groups (also sometimes called aliases), which are variables that denote a group of users. To specify a mail group, place a line of the form:

group name {userId}+ 


into the mail startup file. You may then use name as an alias for the specified list of users, either on the command line or in command mode.



[Page 100]

Figure 3-76 is a list of the most useful mail commands that are available from command mode.

Figure 3-76. mail commands.

Command

Meaning

?

Display help.

copy [mesgList] [fileName]

Copy messages into fileName without marking them as "saved."

delete [mesgList]

Delete specified messages from system mailbox.

file [fileName]

Read mail from mailbox fileName. If no filename is given, display the name of the current mailbox together with the number of bytes and messages that it contains.

headers [message]

Display page of message headers that include message.

mail { userId }+

Send mail to specified users.

print [ mesgList ]

Display specified messages using more.

quit

Exit mail.

reply [mesgList]

Mail response back to senders of message list.

save [mesgList] [fileName]

Save specified messages to fileName. If no filename is given, save them in a file called "mbox" in your home directory by default.


In these commands mesgList describes a collection of one or more mail messages using the syntax shown in Figure 3-77.

Figure 3-77. Message designators in mail.

Syntax

Meaning

.

Current message.

nn

Message number nn.

^

First undeleted message.

$

Last message.

*

All messages.

nn-mm

Messages numbered nn through mm inclusive.

user

All messages from user.



[Page 101]

As you'll see in the examples that follow, these mail commands may be invoked by their first letter only; i.e., you can use "p" instead of "print."

3.38.1. Sending Mail

The easiest way to send mail is to enter the mail directly from the keyboard and terminate the message by pressing Control-D on a line of its own:

$ mail tim            ...send some mail to the local user tim. Subject: Mail Test    ...enter the subject of the mail Hi Tim,  How is Amanda doing? - with best regards from Graham ^D     ...end of input; standard input is sent as mail. $ _ 


I wanted to create a mail group called "music" that would allow me to send mail to all of the people in my band. To do this, I created a file called ".mailrc" in my home directory to look like this:

group music jeff richard kelly bev 


This allowed me to send mail as follows:

$ mail music         ...send mail to each member of the group. Subject: Music Hi guys  How about a jam sometime? - with best regards from Graham. ^D                   ...end of input. $ _ 


For mail messages that are more than just a few lines long, it's a good idea to compose the message using a text editor, save it in a named file, and then redirect the input of mail from the file:

$ mail music < jam.txt       ...send jam.txt as mail. $ _ 


To send mail to users on the Internet, use the standard Internet addressing scheme "user@hostname":

$ mail glass@utdallas.edu < mesg.txt     ...send it.  $ _ 



[Page 102]

3.38.2. Reading Mail

When mail is sent to you, it is stored in a file called "/var/spool/mail/<username>", where <username> is equal to your login name. Files that hold mail are termed "mail folders." For example, my own incoming mail is held in the mail folder "/var/spool/mail/glass." To read a mail folder, type mail followed by an optional folder specifier. You are notified if no mail is currently present:

$ mail    ...try reading my mail from the default folder. No mail for glass $ _ 


If mail is present, mail displays a list of the incoming mail headers and then prompts you with an ampersand. Press Enter to read each message in order, and press q(uit) to exit mail. The mail that you read is appended by default to the mail folder "mbox" in your home directory, which you may read at a later time by typing the following in your home directory:

$ mail -f mbox     ...read mail saved in the mbox folder.


In the examples that follow, I've deleted some of mail's verbose information so that the output fits in a reasonable amount of space. In the following example, I read two pieces of mail from my friend Tim and then exited mail:

$ ls -lG /var/spool/mail/glass        ...see if mail is present. -rw-------  1 glass     758 Mar 12  14:32 /var/spool/mail/glass $ mail                        ...read mail from default folder. Mail version 8.1 6/6/93.  Type ? for help. "/var/spool/mail/glass": 2 messages 2 unread >U  1 tim@utdallas.edu Sat Mar 12 14:32 11/382  Mail test  U  2 tim@utdallas.edu Sat Mar 12 14:32 11/376  Another & <Enter>      ...press enter to read message #1. From tim@utdallas.edu Sat Mar 12 14:32:33 2005 To: glass@utdallas.edu Subject: Mail test hi there & <Enter>      ...press enter to read message #2. From tim@utdallas.edu Sat Mar 12 14:32:33 2005 To: glass@utdallas.edu Subject: Another hi there again & <Enter>      ...press enter to read next message. At EOF      ...there are none! & q      ...quit mail. Saved 2 messages in /home/glass/mbox $ _ 



[Page 103]

To respond to a message after reading it, use the r(eply) option. To save a message to a file, use the s(ave) option. If you don't specify a message list, mail selects the current message by default. Here's an example:

& 15       ...read message #15. From ssmith@utdallas.edu Tue Mar 15 23:27:11 2005 To: glass@utdallas.edu Subject: Re: come to a party The SIGGRAPH party begins Thursday NIGHT at 10:00 PM!! Hope you don't have to teach Thursday night. & R       ...reply to ssmith. To: ssmith@utdallas.edu Subject: Re: come to a party Thanks for the invitation. - see you there ^D       ...end of input. & s ssmith.party      ...save the message from ssmith. "ssmith.party" [New file] 27/1097 & q       ...quit from mail. $ _ 


Caution: "R" replies to the sender and "r" replies to everyone. This is not very intuitive and causes many people some problems when they reply to everyone in the header of the message when they only intended to respond to the sender.

It's possible that you'll receive quite a bit of "junk mail"; to delete messages that aren't worth reading, use the d(elete) option:

& d1-15         ...delete messages 1 thru 15 inclusive. & d*            ...delete all remaining messages. 


3.38.3. Contacting the System Administrator

The system administrator's mailing address is usually "root" or possibly "sysadmin." Typically, the alias "postmaster" should direct mail to the person in charge of e-mail-related issues.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net