3.38. Electronic Mail: mailIt 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-76 is a list of the most useful mail commands that are available from command mode.
In these commands mesgList describes a collection of one or more mail messages using the syntax shown in Figure 3-77.
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 MailThe 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. $ _ 3.38.2. Reading MailWhen 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 $ _ 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 AdministratorThe 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. |