Introduction to UNIX
Electronic Mail Exercises


Sending Mail - Basic Example

  1. Open a new window or use an existing window for this exercise. Then make sure that you are in the Email subdirectory:
    
         cd ~/Email
         

  2. Begin a mail message to yourself. You'll need to know your student userid and the name of your classroom login machine. Your student userid is your login userid. To find your machine's name, type the hostname command.

    Then begin the mail message by issuing the following command - being sure to substitute your userid for "studntXX" and your machine name for "nodeX.class.mhpcc.edu".

    
         mail  studntXX@nodeX.class.mhpcc.edu
         

  3. When prompted for the subject, make one up and then press the Return key.

  4. You are now ready to type the actual mail message. Try typing several lines.

  5. When you are ready to send the message, type CTRL-D. You will be prompted to Cc: someone, but just hit the Return key to ignore it. Your mail is immediately sent.

  6. Return to the tutorial to learn about the next section before proceeding.

Send Mode Commands

  1. Start another mail message to yourself as before, being sure to substitute your userid for "studntXX" and your machine name for "nodeX.class.mhpcc.edu"
    
         mail  studntXX@nodeX.class.mhpcc.edu
         
    Type in a subject and then a line or two of actual message.

  2. Quitting a mail message: There will be times when you will not want to send the message after you have started it. The ~q, typed as the very first two characters on a line will permit you to do this. Use the ~q send mode command to quit this message.

  3. Displaying help: Begin another mail message to yourself. Type in a subject and then a line or two of actual message. Then use the ~? send mode command to display send mode help. Remember that all send mode commands must be the first two characters on a line - otherwise, they will just end up as part of the message text.

  4. Displaying the message buffer: Type in a few more lines. Then use the ~p command to display the progress of your message so far.

  5. Changing the subject line: You may wish to change a message's subject line before you send it. Type the following command to do this:
    
         ~s This is a New Subject
         

    You may be confused and think this will become part of your mail message because it appears to be in the message body. To prove that the command did what it was supposed to do, use the ~p command to display the true contents of the mail message.

  6. Reading in other files: Email is useful for more than just friendly correspondence. It is often used for sending documents, data, images and even executable computer programs. These files can be read into a mail message with the ~r command.

    Read the file add.me into your mail message by using the command below. Be sure to use the ~p command to display the mail message afterwards.

    
         ~r  add.me
         

  7. Writing out to other files: You can always save a mail message you are in the middle of creating by using the ~w command. This is useful if you have to leave and can't finish the mail message right now. If you save it, you can pick up where you left off later by reading the file into a new mail message. Try the command below, noting that a confirmational message will display after the file is saved.
    
         ~w saved.message
         

  8. Using other editors: Let's face it, the default mail editor is not useful for more than one line messages. You will almost always want to invoke a different editor. Try one or both of the following.

    You will learn later how you can create a mail configuration file so that mail will know where pico (or any other editor) is installed. Then you will not be required to use the ~:set command above.

  9. Finish this mail file and send it to yourself by using the CTRL-D send mode command.

  10. Sending Files Directly: You can send a file directly, bypassing the usual interactive mail prompts. Try the command below to send the "add.me" file to yourself. Don't forget to substitute your own student userid and local machine name.
    
         mail studntXX@nodeX.class.mhpcc.edu  <  add.me
         

  11. Return to the tutorial to learn about the next section before proceeding.

Reading Mail

  1. Starting mail in command mode: By now, you have sent several messages to yourself. These have been stored by the system. To read them, simply type the command mail. Your indexed list of messages will appear.

    Compare your indexed list against the tutorial's to understand the information which is being displayed. In particular, notice the:

    The & prompt is your clue that you are in mail's command mode. You are not sending or editing messages to others - you are "doing" your own mail.

  2. Reading the current message: Read the current message by typing t or pressing the Return key. What happens? When the message is completely displayed, the & prompt will indicate that mail is ready to receive another command.

    If the message is more than one screen in length, it will probably scroll off the screen (this is system dependent). To prevent this, you can specify a "pager" program in the mail configuration file - which will be covered later.

  3. Reading the next message: You can read the next message simply by typing n or hitting the Return key at the mail command prompt (&). Try both. If you get to the end of your messages, mail will tell you At EOF , which means, "At End Of File".

  4. Reading any message: You can read any message simply by typing its message number at the mail command prompt (&). Read the first message again by typing the number 1 at the mail command prompt (&). Try the same with another message number.

  5. Return to the tutorial to learn about the next section before proceeding.

Command Mode Commands

  1. Getting help: Type the command ? to see the command mode help.

  2. Displaying the message headings: The message heading list can be displayed by typing h at the mail command prompt (&). This is useful to know if you forget which message is which. You can also use the f command to display message headings for a range of messages. Try these commands:
    
         h
         f
         f *
         f 1-2
         

  3. Deleting messages: Delete the first message in your mailbox with the command d1. Display your message headings with the h command to confirm that it was deleted. Note that using the d command without a message number will delete the current message. Also, the d command accepts a list of messages or the wildcard character (*) as arguments.

  4. Undeleting messages: Undelete the previously deleted message by using the u command. Display your message headings with the h command to confirm that it was undeleted. Note that the u command accepts a list of messages or the wildcard character (*) as arguments.

  5. Replying to messages: The r and R commands are used for this...however, since the only mail which you've received is from yourself, you'll have to try these with real mail later. Sorry.

  6. Sending a new mail message: Use the command below to send another mail message to yourself. This will put you into mail's send mode. Create a message and then send it off. You will see it the next time you start up mail in command mode. Don't forget to substitute your userid and machine name as appropriate.
    
         m studntXX@nodeX.class.mhpcc.edu
         

  7. Issuing UNIX commands from within mail: To issue any UNIX command from within mail, simply preceed that command name with an exclamation mark. Try the following:
    
         !ls
         !ls -l
         !date
         !man cp
         

  8. Quitting mail: You can exit mail with either the x or the q commands. If you choose x, then your previous mail box commands (such as deletes) will not be retained and your mail will be saved as though it was unread in the system mailbox.

    If you choose q, then your mail box commands will be applied and your read messages will be placed into a file called mbox in your home directory.

    Quit mail by using the q command. Check your home directory for a file called mbox. It contains your undeleted, read mail.

  9. Return to the tutorial to learn about the next section before proceeding.

Saving Mail and Using Folders

  1. Understanding mbox: Mail will usually start by trying to read your system mailbox, located in a "system" location, such as /usr/spool/mail/studntXX. This is where your new, unread mail is kept.

    Your previously read mail, however, will be kept in a file (folder) called mbox in your home directory. Assuming that you have completed the previous exercises, you should have several mail messages stored in the mbox folder.

    Change directory to your home directory and make sure your mbox file exists:

    
         cd        
         ls -l mbox
         
    Assuming it does, start mail using your mbox folder:
    
         mail -f  mbox
         

  2. Saving mail messages to a folder While you are in mail's command mode, you can use the s command to save mail to another file/folder. For example, to save the current mail message to a new file/folder, type the command:
    
         s new.folder
         
    Try saving at least two or three messages to the folder new.folder

  3. Accessing other folders: The folder command can be used to access folders of mail files. Note that folders are created by you for organizational purposes. It is up to you to remember where you have stored things!!

    Access the new.folder with the command folder new.folder It should contain the files you saved in the previous step.

  4. Returning to a folder: Now that you know that mail messages are stored in text files, you can return to any folder simply by using the folder command. To get back to your mbox folder, type the command below:
    
         folder mbox
         

  5. Default folder location and folder shorthand notation: You can specify a directory where mail folders are located by default. This requires a few setup details however.

    1. First, get out of mail. Use the x or q command.
    2. Create a folder directory. For example, use the command mkdir Mail
    3. Set a pointer to this location. This can be done several ways. For this exercise, issue the command setenv folder Mail

    Start up mail with your mbox folder using the command mail -f mbox

    Mail provides a shorthand for saving files into folders. Since you have done the necessary setup, you can abbreviate the folder pathname specification with a plus sign (+). Save a couple files with the command s +dakine

    Now access this folder by the mail folder shorthand: folder +dakine You should see the mail messages you saved from the previous step.

    Experiment more if you wish. When you're done, exit mail with the q command. Note that if you list the contents of your Mail subdirectory, you will see the folder you created above.

  6. Return to the tutorial to learn about the next section before proceeding.

Customizing Your Mail Environment

  1. Examine your system's default mail configuration options with the command
     
         cat /usr/lib/Mail.rc 
         

  2. Begin an editing session and create a new file in your home directory called .mailrc - note that it's name begins with a "dot", so that it will be a "hidden" file.

  3. In your .mailrc file, specify some mail options. To begin with, you may wish to try the example from the tutorial:
    
         # Simple .mailrc file
         #
         set ask askcc EDITOR=/source/local/bin/pico folder=Mail 
         set PAGER=more crt=20
         

  4. Try mail now. Determine how the options in your .mailrc file affect your mail session.

  5. Return to the tutorial to learn about the next section before proceeding.

Pine: One Alternative to UNIX Mail

This exercise will acquaint you with the basics of the pine mail system. Pine includes many additional features not reviewed here. It is assumed that these can be learned "on your own" since pine is so easy to use and its online help is so complete.

  1. Start pine: Make sure that you are in your home directory. Then type the command pine. Since this is your first session, you will receive a screen full of information from pine. Read the information carefully. Two important points to remember are mentioned:

  2. Main Menu: After reading the opening message, press any key to continue. You should then see the pine main menu. Take a moment to familiarize yourself with this menu.

    You may also see a message about INBOX. This is what pine calls your incoming mailbox. If you had any messages left there from the previous exercises, pine will notify you. It will also tell you if there are none.

  3. Online documentation: Pine includes an online manual. From the Main Menu, type the help command ? to access the built in documentation. Notice the commands which appear at the bottom of the screen. Press the space bar to see the next page. Read at least several pages of the documentation and then type M to return to the Main Menu.

  4. Compose a message: From the Main Menu, type C to begin composing a mail message. You will immediately enter the compose screen. Notice the new commands which appear at the bottom of the screen. In particular, notice that they are all "Control" character commands. Pine uses the "caret" character (^) to designate CTRL. You may also recognize that these commands are actually pico editor commands. Pine uses pico by default.

    Notice that the "To:" line is highlighted. This tells you that pine is ready to have you type in the email address of this message's recipient. Send the message to yourself, being sure to substitute your userid for "studntXX" and your machine name for "nodeX.class.mhpcc.edu" as you did in the previous mail exercises:

    
         studntXX@nodeX.class.mhpcc.edu
         
    Fill in the Subject: field and then type a couple of lines of message. When you're ready to send the message, type the ^X command to send it. Pine will prompt you for confirmation - type y to confirm. The message will be sent and you will be returned to the Main Menu.

    Send at least three additional messages to yourself. Notice that pine will notify you whenever a message arrives.

  5. Getting help: Pine includes an excellent, context-sensitive help system. As an example, enter the "Compose Message" screen. Move your cursor to various fields on the screen, such as the "To:" field, the "Subject:" field, etc. As you do this, get help on each field with the ^G command. Take a few moments to read the help. To exit help, use the E command.

    When you're done exploring the help for the compose screen, use the ^C command to cancel the compose and return to the Main Menu.

  6. Reading your mail: Your incoming mail is kept in pine's INBOX folder. By default, this is the current folder. From the Main Menu, view the INBOX index with the I command. You will immediately go to the folder index screen. The messages you sent previously should be visible now.

    The current message will be highlighted. Press the Return key to read it. The message will display, as will new command options. After reading the message, move to the next message by typing the N command.

    Try accessing the help screen by typing the ? command. Type the E command to exit help.

    You can return to your folder index when you are done reading mail messages by using the I command. Try this. Then use the up and down arrow keys to select different mail messages. Notice how the index changes as you read messages (the N - new message indicator is removed after a message is read).

  7. Saving mail to a folder: Pine allows you to create and use folders for organizing your mail in much the same way as UNIX mail. Try saving a couple messages to a new folder by following the steps below:

    1. Go to the INBOX folder index screen if you are not already there

    2. Select any message to save by using your up/down arrow keys to highlight the message

    3. Type the S command. You will be prompted to enter the name of the folder. Type the name new.folder

    4. You should then see a message that says "Folder "new.folder" doesn't exist. Create? (y/n) [y]:" - type y to confirm.

    5. Pine will copy the message to the folder (kept in the mail subdirectory). You will then see an informational message which says " [Message 2 copied to folder "new.folder" and marked deleted]".

      Pine assumes that once you save a message to a folder, it is no longer needed and so, marks it for deletion. You can "undelete" the message by simply typing the U command.

    6. Save at least one other message to the same folder. Notice that since this folder now exists, you won't see the same prompts as before.

    7. Go back to the Main Menu by typing the M command.

  8. Changing folders: Pine makes moving between folders very easy. Follow the steps below to see for yourself.

    1. Go to the Main Menu if you are not already there. Then use the L command to view a list of your available folders. You will immediately go to the folder list screen.

    2. Review the folder list screen. You should see four folders, including the folder "new.folder" which you just created. The other folders, INBOX, sent-mail and saved-messages are created by pine automatically.

    3. Use the right arrow key until the folder "new.folder" is selected/highlighted. Press the Return key to enter that folder. You should see an index of the messages you previously saved.

    4. Type the O command to see a few additional commands. Notice the L command. Using this command will take you back to the folder list screen. Go ahead and try it.

    5. Now use your left arrow key to select the INBOX folder. Press the Return key when it is selected. You will now be in your INBOX folder again.

  9. Quitting pine: You can exit your pine session at just about any point by typing the Q command. Pine will "clean up" the INBOX by removing messages marked for deletion (it will ask for your confirmation first) and then save the remaining messages in the INBOX folder.

  10. Customizing pine: You can edit the .pinerc file which pine automatically created for you to change certain aspects of pine's behavior. This exercise is left up to the reader.

  11. This concludes the Electronic Mail exercises. Return to the Electronic Mail tutorial or to the Table of Contents.