Sun Microsystems, Inc.
spacer |
black dot
  Previous   Contents   Next 
Chapter 7

Using Mail

SunOS provides a program called mailx for sending and receiving electronic mail (email). mailx provides features for reading, writing, sending, receiving, saving, and deleting messages. The mailx program is not window based, and can therefore be run on any terminal. Although you might prefer to use the window-based mail, you might find that the mailx program is handy when you are dashing off a quick note. Also, if you want to set up your own mail aliases, you can read about it here.

Note - If you are in a window environment and the Mail Tool icon appears on your screen, quit from the Mail Tool before trying the examples in this chapter. Otherwise, you will have two mail processes active, and these concurrent processes might generate error and warning messages. You can safely send mail messages in a Command Tool or Shell Tool window, but if you read your mail and save or delete messages, this affects your "in tray," thus confusing Mail Tool.

mailx Basics

This section describes how to perform basic tasks in mailx. Later sections describe features and functions that can enhance your ability to use this program.

An intended recipient's login name and machine name serve as a unique address for the mailx program. If the intended recipient is on the same machine as the sender, the login name is all that is required. Each user has a mailbox in which to receive mail. This mailbox is generally located in the /var/mail/username directory, where username is your login name.

The mailx program notifies you when you receive mail and places the mail in your mailbox. After you read your mail, mailx automatically places these messages in a storage file called mbox, which is also located in your home directory.

Starting mailx

Start mailx by typing the following command at a prompt and then pressing the Return key:

$ mailx

If you don't have any mail waiting for you, your terminal displays the message:

No mail for username $

In this message, username is your login name.

Sending Yourself a Sample Message

To see at a glance how mailx works, you can begin by sending yourself a sample message. At the prompt, give the mailx command again, but this time include your address (your login name plus your machine name). For example, if your login was rose and your machine name was texas, your address would be rose@texas. (The @ symbol is read as "at.") You might be able to use just your login on a local network--consult your system administrator when in doubt.

$ mailx rose@texas

The program responds with a Subject: line:

$ mailx rose@texas

If you like, type a word or two here about the content of the message you're sending yourself and press Return. Now type the body of the message. Use short lines and press Return at the end of each line. Note that you can only make corrections as you go by moving back a space and retyping lines before you press Return.

Your sample message might look something like this (the spaces between lines are made by pressing Return twice):

$ mailx rose@texas
Subject: to someone who really cares

Dear Rosey,

From the ends of your fingers
To the tip of your nose
You're a cool breeze in August
My sweet Texas Rose.

See you soon,


To send your sample message, press Return to complete the last line of the message and then press Ctrl-D. After your message has been sent, the system returns a command prompt.

Reading Your Sample Message

To read your sample message, use the mailx command again. Your screen should look something like this:

$ mailx
Mail version 4.0 Thu Jan 16 12:59:09 PST 1992  Type ? for help.
"/var/mail/rose": 2 messages 1 new
 U  2 hal@uncertain   Fri Feb 14 12:01   14/318 financial status
>N  1 rose@texas      Mon Feb 17 08:12   21/453 to someone who

The first line identifies the version of mail that you are running. The second line indicates your mailbox, usually located in /var/mail/username, where your incoming mail is deposited. The third line in this example is the header of the message you sent yourself. The "N" at the beginning of the line means that it's a "new" message. A "U" (unread) means the message was new, but was not read before quitting the mailx program previously. The information in this screen is discussed in greater detail in "Reading Messages".

Every message is assigned a number as it is received: Rose's message to herself is shown as message number 1.

To read a message, type an ampersand (&) and the message number at the mailx prompt, as follows:

& mailx
Mail version 4.0 Thu Jan 16 12:59:09 PST 1992  Type ? for help.
"/var/mail/rose": 1 message 1 new
>N  1 rose@texas   Fri Jul 14 12:01 21/453 to someone who
& 1

To: rose@texas
From: rose@texas
Subject: to someone who really cares

Dear Rose,

From the ends of your fingers
To the tip of your nose
You're a cool breeze in August
My sweet Texas Rose.

See you soon,



Quitting mailx

When you have finished your work in mailx, you can quit the program by using one of two commands: q (quit) or x (exit).

If you type q at the mailx prompt and then press Return, you see a message similar to the following:

Saved one message in home_directory/mbox.

In this message, home_directory is the path name to your home directory.

When you use q to quit mailx after reading messages, mailx moves the messages from your mailbox and saves them in the mbox file in your home directory. mailx also saves any changes or deletions you've made.

If you type x at the mailx prompt and then press Return, the mailx program does not save any changes or deletions, nor does it move any messages you've already read into the mbox file.

Reading Messages

If you have mail, mailx notifies you each time you log in with the message

You have mail


You have new mail

To read your messages, type mailx at a command prompt and press Return. If no mail is waiting for you, you will see the message:

No mail for username

Otherwise, you see a list similar to the following:

$ mailx
Mail version 4.0 Thu Jan 16 12:59:09 PST 1992  Type ? for help.
"/var/mail/rose": 4 messages 1 new 2 unread
    1 rose@texas        Fri Feb 14 12:01 21/453 to someone who
 U  2 hank@fretful      Fri Feb 14 18:31 19/353 so lonely I
 U  3 farmer@freeway    Sat Feb 15 10:22 24/557 looks like my
>N  4 hoover@woofer     Sun Feb 16 23:59 14/280 big old furry


The mailx program displays information about itself (version number and date) and instructions for getting help (Type ? for help).

On the next line, mailx specifies the location of your mailbox, the number of messages received, and their status.

Next, mailx shows a numbered list of the messages in your mailbox. From left to right, the columns in each line specify:

  • Status: Indicates whether a message is new (N), unread (U), or read (no symbol). A ">" at the beginning of a line indicates the current message. Deleted messages are marked with an asterisk (*).

  • Number: Indicates the order in which message was received.

  • Sender: Indicates the name of the user (and usually machine) the message came from.

  • Time: Indicates the date and time the message was sent.

  • Size: Indicates the number of lines or the number of characters in message.

  • Subject: Indicates the sender-designated subject of the message.

  Previous   Contents   Next