Introduction to Unix Mail

This document describes:

Introduction to Unix Mail

The following assumes that you have a login ID and password on a machine that runs some version of Unix (e.g., BSD 4.3, System 5, SunOS 4.1.x, etc.). It is assumed that the name of the machine on which your login ID exists is "unixhost", and your login ID is "me". Throughout this document, the following conventions have been adopted.

Messages from the operating system will appear in a nonproportional font:

          unixhost[1]:
Commands issued by the user will appear in a bold nonproportional font:
          mail biggie
Keystrokes that should be issued exactly as presented will appear in <BRACKETS>. For example, <RETURN> indicates striking the key marked RETURN on the keyboard.

1) Sending mail to a local user

For this example, send mail to your friend biggie.
          unixhost[1]: mail biggie
          Subject: Testing
After you type your choice of "Subject:" (or striking <RETURN> for no subject), the cursor will go to the next line and wait for input. You should type your message now. Remember that the mail composition facility does not have auto-wrapped lines, which means that you must type <RETURN> at the end of each line, much like a typewriter. In fact, only <BACKSPACE> is functional; all other directional keys (like the arrow keys) are not functional. When you have finished typing your message, strike <RETURN> to bring the cursor to the next line. With the cursor in the first column of a new line, type a single period (i.e., <.>) and strike <RETURN> (some systems require that you hold the key marked CTRL and strike the D key, a sequence that is commonly referred to as <CTRL-D>). This is the signal to the mail composition facility that you have finished typing your letter and it's ready to send. For example:
          unixhost[1]: mail biggie
          Subject: Testing
          Biggie:  This is a test message.  Let me know if you get it.
          .
          Cc: 
The prompt "Cc:" is for carbon copies. The same mail message can be sent to multiple recipients (like written correspondence) using the "Cc:" function. If there are other recipients for this message, you should type their login IDs now. Otherwise, you should strike the <RETURN> key.
          unixhost[1]: mail biggie
          Subject: Testing
          Biggie:  This is a test message.  Let me know if you get it.
          .
          Cc:
          unixhost[2]: 
When the system prompt returns, the mail message has been sent to the delivery system for immediate delivery.

2) Manipulating mail messages from a local user

Suppose biggie were to send a mail message to you. You can read that and other e-mail messages as follows:
          unixhost[3]: mail
          Mail [5.2 UCB] [IBM AIX 3.1] Type ? for help.
          "/usr/spool/mail/me:" 1 message 1 new
          >N  1 biggie      Thu Aug  6 10:37  11/365 "Testing"
          &
The command "mail" with no recipients will check your mailbox for any messages. If you have any messages, they will appear as shown above. The example message is from biggie and it is new. This can be determined by the "N" in front of the mail item (meaning New), and the sending ID (biggie). The number that appears just before the loginID is the message number. This number will be used in virtually all manipulations of this message. The day/date/time stamp indicate the time that it was delivered to you, the number following the time stamp (e.g., 11/365) indicates the number of lines and bytes in the message (e.g., 11 lines, 365 bytes), and the text following the byte count is the given subject of the message. The ">" sign in front of the message indicates the current message. This is more meaningful when there are multiple messages.

The commands that will be described here are a subset of the commands available in the mail program.

To get a list of the commands available in mail, you may strike the <?> key at the mail prompt. This will produce the following output:

     
          & ?
          Control Commands:
           q                  Quit - apply mailbox commands entered this session
           x                  Quit - restore mailbox to original state.
           ! <cmd>            Start a shell, run <cmd>, and return to mailbox.
           cd [<dir>]         Change directory to <dir> or $HOME.

          Display Commands:
           t [<msg_list>]     Display messages in <msg_list> or current message.
           n                  Display next message.
           f [<msg_list>]     Display headings of messages.
           h [<num>]          Display headings of group containing message <num>

          Message Handling:
           e [<num>]               Edit message <num> (default editor is e).
           d [<msg_list>]          Delete messages in <msg_list> or current
                                   message.
           u [<msg_list>]          Recall deleted messages.
           s [<msg_list>] <file>   Append messages (with headings) to <file>.
           w [<msg_list>] <file>   Append messages (text only) to <file>.
           pre [<msg_list>]        Keep messages in system mailbox.

          Creating New Mail:
           m <addrlist>            Create/send new message to addresses in
                                   <addrlist>.
           r [<msg_list>]          Send reply to senders and recipients of
                                   messages.
           R [<msg_list>]          Send reply only to senders of messages.
           a                       Display list of aliases and their addresses.
Using the above commands, displaying a message includes issuing the "t" command with the message number and striking <RETURN>. In this case, you would issue the following commands:
          unixhost[3]: mail
          Mail [5.2 UCB] [IBM AIX 3.1] Type ? for help.
          "/usr/spool/mail/me:" 1 message 1 new
          >N  1 biggie      Thu Aug  6 10:37  11/365 "Testing"
          & t 1
          Message  1:
          From biggie Thu Aug  6 10:37:39 1992
          Date: Thu, 6 Aug 92 10:37:39 -0500
          From: biggie (Tommy Fritsche,  Trinity 2)
          To: me
          Subject: Testing

          This is a test reply.  I received your message fine.

          (EOF):
At the "(EOF):" prompt, strike the <RETURN> key, and you will be returned to the Mail prompt (i.e., "&").

There are a number of options available to you now. You can read the message again from the beginning by issuing the "t 1" command and striking <RETURN> at the Mail prompt. You may also wish to reply to the message. To do this, you must issue an "R" command with the message number and strike <RETURN> at the Mail prompt:

          & R 1
          To: biggie
          Subject: Re:  Testing
This will start creating a mail message to biggie. Type your message, strike the return key to go to the beginning of a new line, type one <.>, and strike <RETURN>:
          & R 1
          To: biggie
          Subject: Re:  Testing

          This is a test reply.
          .
          Cc: 
          &
Notice that the Cc: option is still in effect, so you can send copies of your reply to others, if you wish. One word of warning is that the command "r", which is similar in intent to "R", is functionally very different. When you issue the "R" command, you are sending a reply only to the person whose address appears in the To: field.

When you use the "r" command, you are replying to that person, in addition to all addresses that appear on the Cc: line of the original message that was sent to you. In a great many instances, the two commands are functionally similar. However, when there are a number of Cc: recipients, you should be aware that the reply using "r" will send your mail message to each of them.

You may also wish to delete the message, in which case, you would issue a "d" command with the message number and strike <RETURN> at the Mail prompt:

          & d 1
          &
The mail program issues no messages when it deletes mail items.

You may also wish to take no action or to exit the mail reader after manipulating mail items. To do this, you must issue a "q" command at the Mail prompt:

          & q
          Held 1 messages in /usr/spool/mail/me
          unixhost[4]: 
You may also exit the mail program and cancel any changes you may have made. For example, suppose you have deleted a mail message that you wish to keep. In reality, the message will be marked for discard, and will not actually be discarded until you exit the mail program. To exit the mail program without discarding the message that you have marked for removal you must issue the "x" command at the mail prompt. This will return you to the unix system prompt, and will not discard the mail message.

Assume further that you receive another message from some other person on your machine. Now when you issue the mail command, the message you received from biggie will still be in your mailbox, along with a new message:

          unixhost[4]: mail
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help
          "/usr/spool/mail/me": 2 messages 1 unread
              1 biggie      Thu Aug  6 10:37  12/376 "Testing"
          >N  2 annie       Thu Aug  6 11:51  12/350 "Hello"
          &
Notice the new message (marked with "N") is message number 2 and is from login ID annie. To read this message, issue the "t" command with the message number and strike <RETURN> at the Mail prompt:
          unixhost[4]: mail
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help.
          "/usr/spool/mail/me": 2 messages 1 unread
              1 biggie      Thu Aug  6 10:37  12/376 "Testing"
          >N  2 annie       Thu Aug  6 11:51  12/350 "Hello"
          & t 2
          Message  2:
          From annie Thu Aug  6 11:51:46 1992
          Date: Thu, 6 Aug 92 11:51:45 -0500
          From: annie (Annie Fritsche,  Trinity 1)
          To: me
          Subject: Hello

          Hello.  I'm just testing e-mail.

          Annie.

          (EOF):
          &
You may also read the mail item you received from biggie by issuing the "t" command with it's message number (i.e., 1) and striking return:
          & t 1
          Message  1:
          From biggie Thu Aug  6 10:37:39 1992
          Date: Thu, 6 Aug 92 10:37:39 -0500
          From: biggie (Tommy Fritsche,  Trinity 2)
          To: me
          Subject: Testing

          This is a test reply.  I received your message fine.

          (EOF):
          &
It is also possible to forward a mail message that you have received to another user. To forward a mail message, you would issue the "mail" command as described above and answer whatever questions are asked (e.g., Cc:). Once you have answered the questions and have been placed in the mail editor, you would issue the "~m" command, with the message number of the message you wish to forward. For example, suppose you received the above mail message from annie and you wanted to forward it to biggie. The mail message for biggie is message #1 and the mail message from annie is message #2. The commands would look like this:
          unixhost[4]: mail
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help.
          "/usr/spool/mail/me": 2 messages
          >   1 biggie      Thu Aug  6 10:37  12/376 "Testing"
              2 annie       Thu Aug  6 11:51  12/350 "Hello"
          & m biggie
          Subject: Look at this ...
          ~m 2
          Interpolating: 2
          (continue)
          .
The contents of message #2 are placed in the body of the mail message to biggie and are offset by one tab character. This command may be issued at any time during the composition of the mail message, with the proviso that the command be issued from column 1 of any line. With this, you can add your own editorial comments before or after the message. When you are ready for the mail message to be delivered, type <.> in column 1 of a new line.

There are some things to remember. You may always look at the headers of the mail items (i.e., the way it looked the first time you issued the command "mail") by issuing the command "h" from the mail prompt:

          & h
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help.
          "/usr/spool/mail/me": 2 messages
          >   1 biggie      Thu Aug  6 10:37  12/376 "Testing"
              2 annie       Thu Aug  6 11:51  12/350 "Hello"
You should note that the ">" sign now points to the message from biggie (message #1). That is the message that was handled most recently, and is therefore the current message. Furthermore, notice that the "N" is missing from the message from annie. This is because you have read the message, and it is no longer new. With the ">" pointing to the message from biggie, issuing any read/reply/discard/save commands will be made with respect to that message. For example, if you issue the "R" command, you will be replying to biggie. Likewise, if you issue the "d" command, you will delete the message from biggie. It is also possible to delete both messages at once:
          & d1-2
          &
Again, notice that no messages are issued when mail items are deleted. The "d" command is fairly versatile, and can be used in a number of different ways:
          & d1-2 3 5-7
          &
deletes messages 1 and 2, message 3, and messages 5, 6, and 7.
          & d*
          &
deletes all messages, regardless of the number of messages involved.

3) Electronic mail interaction with a remote machine

Before discussing mail to users on other machines, we must first discuss the naming conventions of the Internet. The Internet is a very large computer community that provides many useful services. In order to belong to the Internet, member computers must adhere to the naming convention adopted by the Internet. Computers on the Internet address and communicate with one another using unique numeric addresses (called Internet numbers or IP addresses) that are assigned to member computers. The users of Internet services, however, are allowed to address and communicate with member computers with names (called Internet names). These names, like IP addresses, are themselves unique and are uniquely mapped to IP addresses.

To explain the Internet naming convention and the way in which L.S.U. implements this convention, it's best to list a name/address pair and describe the parts:

          sn01.sncc.lsu.edu        130.39.128.20
This machine is the DEC VAX 8800 in SNCC. Internet names are hierarchical in nature, and by convention, names of educational institutions end in .edu. The name lsu.edu, then, should be fairly self-explanatory, and denotes the broadest area of Internet administration on campus. The next portion to the left (sncc.lsu.edu) refers to the machines that are housed in SNCC. Finally, the name sn01 refers specifically to the VAX 8800. The IP address for sn01.sncc.lsu.edu is parsed similarly. All IP addresses on the L.S.U. campus begin with 130.39. The next portion to the right (130.39.128) refers to machines connected to the campus ethernet, and is a campus-wide convention. The last portion (130.39.128.20) refers specifically to sn01.

There are no general rules for the number of administrative divisions there are in an Internet name. By convention, the IP addresses are four octets (e.g., 111.222.333.444). The Internet names on the L.S.U. campus adhere as closely as possible to the following convention:

          machine_name.dept.lsu.edu
where machine_name is the specific name identifier assigned to the computer, dept is the abbreviation for the academic or administrative department to which the machine belongs, and lsu.edu refers to all machines on this campus. Any name of the form host.dept.site.edu is called the Internet Fully Qualified Name (FQN) or the Internet host name of the computer. An example of a campus computer that follows this convention is IBM RS/6000 in the Office of Telecommunications. It's FQN is te6000.otc.lsu.edu:
          te6000         - Telecommunications' RS/6000
          otc            - Office of Telecommunications
          lsu            - Louisiana State University
          edu            - an educational facility
Other sites follow this convention. For example, the FQN for the VM/CMS machine at Tulane University is vm.tcs.tulane.edu:
          vm             - the VM/CMS machine
          tcs            - Tulane Computer Services
          tulane         - Tulane University
          edu            - an educational facility
The general rule for sending mail to users on other machines is as follows:
          mail loginID@host.dept.site.edu
where loginID is the login name of the recipient, and host.dept.site.edu is the Internet FQN of the host computer. The only other warning or advice is that many of the machines connected to the Internet use case-sensitive login IDs and machine names. Therefore, a names like michael, Michael, and MICHAEL would be considered three separate names.

Let's assume for this example that the fully qualified Internet name of your unix machine is unixhost.chem.lsu.edu. Further assume that you have a friend with a login ID on another unix machine, and you wish to send your friend electronic mail. To do this requires that you specify the login ID of that person and the fully qualified Internet name of the machine on which your friend is working. For example, assume your friend's login ID is dave, and his machine is sunmachine.math.lsu.edu. In order to send mail to your friend dave, you would issue the following command:

          unixhost[10]: mail dave@sunmachine.math.lsu.edu
This will result in the following messages:
          unixhost[10]: mail dave@sunmachine.math.lsu.edu
          Subject: Testing e-mail to another machine

          Dave:

          I just figured e-mail out.  How about that?
          .
          Cc:
          unixhost[11]:
The mail interface is no different for sending messages to users on other machines. The only difference is that you must know the name of the machine on which the mail will be read. If your friend sent a reply to your message, it could be read as follows:
          unixhost[12]: mail
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help.
          "/usr/spool/mail/me": 1 message 1 new
          >N  1 dave@sunmachine.math.lsu.edu Thu Aug  6 14:29  27/905 ""
          & t 1
          From dave@sunmachine.math.lsu.edu Thu Aug 6 14:10:55 1992
          Date:         Thu, 06 Aug 92 14:08:39 CDT
          From: Dave Barry 
          Subject:      Re: Testing e-mail to another machine
          To: me@unixhost.chem.lsu.edu
          In-Reply-To:  Your message of Thu, 6 Aug 92 14:07:57 CDT
          Status: OR

          Glad to hear that you figured out e-mail.  Now if you could just program your VCR
          --
          Dave Barry
          Louisiana State University
          (504) 388-3202

          (EOF):
          &
All the other mail commands discussed above can be used with respect to this message.

4) Organizing mail

The concept of folders is central to understanding mail reading and handling. Each time you issue the "mail" command, you are reading a folder. In the Unix operating system, the folder which holds newly received mail is something like "/usr/spool/mail/loginID". This is just a file that contains mail messages that are being read for the first time. You may save messages into folders, whose contents can be displayed and manipulated just like mail items that are new.

To save a message into a folder, you would issue the following command:

          & s +folder_name
For example, suppose you were collaborating with dave@sunmachine.math.lsu.edu on a research grant and you wanted to save all correspondence with dave in a folder. To do this, you would issue the following command:
          & s +barry
This would create a folder called "barry" in your home directory for the newly received message. In addition, the message would be removed from the default mailbox, in this case "/usr/spool/mail/me". Once the message has been saved into a folder, the folders can be displayed and manipulated like new messages as follows:
          & folder +barry
          "+barry": 1 message
          >   1 dave@sunmachine.math.lsu.edu Thu Aug  6 14:29  27/905 ""
You may now use the read/reply/discard functions as described above on the messages in this folder.

Similarly, the "s" command will save multiple messages:

          & s1-2 +new.mail
          "new.mail" [Appended] 58/1693
saves messages 1 and 2 into a folder called new.mail, which already exists.
          & s1-2 3 5-7 +export.data
          "export.data" [New file] 110/2332
save messages 1 and 2, message 3, and messages 5, 6, and 7 into a new folder called 'export.data'.
          & s* +all.mail
          "all.mail" [New file] 766/9242
saves all messages into a new folder called 'all.mail'.

You may also wish to save a mail message without the mail header information that is contained in the message. This would be useful if you were to receive the source code of a program that you will compile on your machine. If you save the message into a file as described above, all the header information will be retained at the top of the file. You may edit the file and remove this information, or you may choose to save the file without this information. To do this, issue the "w" command. The form of the "w" command is exactly the same as the "s" command:

          & w 1 new.file
          "new.file" [New file] 13/200

5) Customizing the mail environment

There are a number of features of mail that you can make default elements of your mail sessions by including them in a file called .mailrc. This is a file of settings and options that is invoked each time the mail program is initiated. For example, a great many users do not want to be asked whether carbon copies are to be enclosed (the Cc: prompt just prior to sending mail). To turn Cc: prompting off, you may issue the following command at the mail prompt:
          & unset askcc
You may also put the line "unset askcc" into the .mailrc file in your home directory. You may also set folder names with the following command:
          & set folder=letters 
You may also put the line "set folder=letters" into the .mailrc file, and the folder "letters" will be your default folder. Another very useful feature is the ability to alias mail addresses. This can be done from the mail command prompt as follows:
          & alias new_name loginID@host.dept.lsu.edu
For that mail session, the alias new_name will refer to the address loginID@host.dept.lsu.edu. For example, to alias your friend dave@sunmachine.math.lsu.edu, you would issue the following command:
          & alias barry dave@sunmachine.math.lsu.edu
Mail aliases are usually used in one of three ways. First, they can be a shorter version of a long e-mail address, as shown above.

They may also be longer but more meaningful names for non-user-friendly loginIDs. For example, you may wish to make someone's last name an alias for their initials, which is their loginID.

          & alias fritsche mbf@te6000.otc.lsu.edu
Finally, you may send mail to multiple users at once by assigning them a group alias:
          & alias kids annie biggie dave@sunmachine.math.lsu.edu
You may now send mail to both annie and biggie, who have login IDs on the same machine as you, and dave@sunmachine.math.lsu.edu by issuing the command "mail kids".

The real utility of the alias function is its use in the .mailrc file. If there is someone with whom you communicate regularly, it is a real savings of time to abbreviate their fully qualified e-mail address. However, if you issue the "alias" command from the "mail prompt", the alias will be lost when you exit the mail program. To make aliases a permanent part of your electronic mail environment, you should put them into the file .mailrc.

6) Interaction with different electronic mail environments

As a general rule, mail can be sent to practically any other e-mail environment, provided the following pieces of information are known:
    1) The properly formatted e-mail address of the recipient
    2) The mail gateway that joins the two mail environments
There are many mail environments on the L.S.U. campus. The major interconnected environments are VM/CMS Mailbook, VAXmail, Unix mail (SMTP), and PC mail. Each of these environments address e-mail slightly differently, and you should be aware of the addressing convention of them so that messages can be addressed accordingly.

In addition, you should be aware of the fact that these mail environments are not necessarily connected. They are connected by machines that are generically referred to as gateways, and these machines are typically members of the two e-mail environments for which they are gateways. For example, the network on which a great many Unix hosts are connected on campus is Internet. Unix mail addresses look like those we have discussed up to now (e.g., me@unixhost.chem.lsu.edu). There are other machines, like the VM/CMS machine, that are connected to a network called BITNET. Generally, these two networks are distinct, and mail sent from one system will not necessarily be delivered to the other. However, there are gateways that connect Internet and BITNET, and sending mail from one system to the other requires both the properly formatted address of the recipient and the addressing convention of the gateway that connects the two systems.

7) Discussion and review

Below is a list of the major topics discussed in this document and some of the important points of these topics:
     *  Sending mail
          mail loginID@fully.qualified.node.name

     *  Manipulating mail
          -  t <msg_number>        Reading (typing) message
          -  R <msg_number>        Replying to message
                                   NOTE:  R replies to "From:" address only
          -  ~m <msg_number>       Forwarding a message
          -  d <msg_number>        Deleting a message

     *  Organizing mail
          -  s +folder_name        (formatted as mail message)
          -  w file_name           (formatted as text file)

     *  Customizing the mail environment
          aliases
          editing .mailrc file

     *  Mail gateways
          properly formatted e-mail address of recipient
          addressing convention of the e-mail gateway
For additional information, you may consult the Unix manual pages for mail. These are available with the command <man mail>. You may also be interested in the ITS classes Introduction to Unix, Introduction to Mail Gateways, and Advanced Electronic Mail Routing. In addition to the on-line help (using the command <man>) and the ITS seminars, there are a great many books about the Unix operating system and electronic mail. At last count, there were 73 books on electronic mail and 46 books on the Unix operating system in Middleton Library.

8) Exercises

     1)  Send a mail message to the to address mailtest@te6000.otc.lsu.edu

     2)  Read the reply mail message sent from mailtest@te6000.otc.lsu.edu and follow the instructions within.

     3)  Suppose you issued the command <MAIL> and received the following:

          unixhost[4]: mail
          Mail [5.2 UCB] [IBM AIX 3.1]  Type ? for help.
          "/usr/spool/mail/me": 2 messages
          >   1 mickey      Thu Aug  6 10:37  12/376 "Squeak"
              2 goofy       Thu Aug  6 11:51  12/350 "Woof"
              3 donald      Tue Sep  8 15:08  14/400 "Quack"

     -  what command would you issue to read the message from donald?

          &


     -  what command would you issue to reply to the message from mickey?

          &


     -  what command would you issue to enclose the message from goofy in your reply to mickey?

          &