Previous Table of Contents Next


APPLICATIONS

You use the mailx command to exchange information with other users. The information may be any ASCII text; for example, memos, notes, program source, data, documents, or whatever information you need to send. The users may be local or remote depending on how your system is set up. If you have links to other systems via a LAN or modem, you can send mail to users on other systems.

TYPICAL OPERATION

In this activity you use the mailx (mail on BSD) command to send yourself a short message. Begin at the shell prompt.


BSD (Berkeley)
If you are on a BSD system use the /usr/ucb/mail command. You can use the which command to locate which mail command your PATH finds first. If it is /usr/ucb/mail, you can just type mail. Otherwise, change your PATH or type in the entire /usr/ucb/mail path. You may wish to set an alias to /usr/bin/mail. For example, place the following command in your .cshrc.
     alias mail /usr/bin/mail.

1.  Type mailx mylogin and press Return. Notice the Subject prompt appears.
     cj> mailx mylogin
     Subject: _
2.  Now type in a brief subject line, Sending mail to myself. and press Return.
     cj> mailx mylogin
     Subject: Sending mail to myself.
     _
3.  Now you are in insert mode. You can type whatever message you wish. If you wish, use the following one. Remember to press Ctrl-D at the beginning of the line to terminate input.
     cj> mailx mylogin
     Subject: Sending mail to myself.

                            April 22, 1989

     Just thought I'd test the mailx command. So I'm sending myself a message. UNIX is a powerful
     system of tools designed to increase productivity among computer users.
     ^D
     cj>

In this activity you invoke mailx to read any mail stored in your mailbox. Start at the shell prompt. You should wait a few minutes before continuing, since the message may still be en route to your mailbox. This is unlikely but on extremely slow systems it is possible.

1.  Type mailx and press Return. Your screen should resemble the following display, although you may not have mail from other users.
    cj> mailx
    mailx version 2.2 9/9/88.    Type ? for help.
    "/usr/mail/mylogin": 2 messages 2 unread
    >O  1  bill      Tue Apr 12 08:31  5/134  "cabling problems"
     O  2  nancy     Tue Apr 12 10:03  4/98   "lunch in the break area"
     N  3  mylogin   Wed Apr 13 09:41  6/213  "Sending mail to myself."
2.  Now you can read your new message. Just type 3 and press Return. Your message is displayed on your screen.
3.  To delete the message type d and press Return. Since you are currently at message 3 no message list is needed. The d command deletes the current message.
4.  Type h and press Return to display the header lines again. Notice the last message is gone.
5.  Type q to quit mailx.

In this activity you send a file you created earlier to a user. Start at the shell prompt.

1.  Type mailx mylogin < first and press Return. This sends the file first to yourself. The mailx command reads the standard input, thus allowing you to use redirection or pipe commands to send messages to specified users. A standard mail header is added to the beginning of the input file.

In this activity you create a .mailrc file to control how mailx function. Start at the shell prompt.

1.  Type cd and press Return to return to your HOME directory.
2.  Type vi .mailrc and press Return. This places you in the .mailrc file.
3.  Now enter the following lines, pressing Return at the end of each line. When you have entered all lines, press Escape and type ZZ to save the file and exit vi.
     cj> vi .mailrc
     i
     set LISTER="ls -xs"
     set MBOX=$HOME/mail/MBOX
     set PAGER="pg -cn -p '/usr/mail/mylogin'"
     set cmd="lp -dlaser"
     set hold
     set EDITOR=vi
     set folder=$HOME/mail
     <Escape>ZZ

BSD (Berkeley)
cj> vi .mailrc
i
set LISTER=ls
set MBOX=$HOME/mail/MBOX
set PAGER=more
set cmd=lp
set hold
set EDITOR=vi
set folder=$HOME/mail
<Escape>ZZ

4.  Since you set variables that require a directory named mail in your home directory, you need to create the directory. Type mkdir mail to create the mail directory.

The following activities will use some of the variables you set in the .mailrc file. In the following activity you use some tilde commands to help you generate a message.

1.  Type mailx mylogin and press Return. Again we send mail to ourselves.
2.  At the subject prompt type Playing with the mailx command! and press Return. Now you are ready to type in your message. You are in insert mode. Enter the following lines exactly as shown in the display.
   cj> mailx nancy
   Subject: Playing with the mailx command!
   This is a brief message about tommorros big design meeting. I need to know if I should order two
   dozen donuts or three?  PLeas  let me know as soon as possible. Thnaks

                      Myself

   ~e
3.  You should now be in the vi editor with your message displayed. Now move around and correct the spelling mistakes in the message. The following list shows the motions and corrections; do not press Return after each line:
   /mm<CR>
   xfsiw<ESC>
   jfL~
   fsae<ESC>
   jFnxp
   ZZ
   (continue)

This will correct the spelling mistakes and save the message to a temporary file. You are placed back in insert mode of mailx.
4.  To send the message press Ctrl-D.
   (continue)
   Ctrl-D
5.  Type mailx and press Return to read the last two messages you have sent to yourself.
6.  Press Return to read the first message or select the appropriate message number and press Return.
7.  Press Return again to read the second message you sent.
8.  Delete all messages from your mailbox by typing d* and pressing Return.
9.  Type q and press Return to quit mailx.
10.  Turn to Module 117 (SV), Module 72 (BSD) to continue the learning sequence.


Previous Table of Contents Next