Solaris Advanced User's Guide

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
Subject:

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,

Rose

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,

Rose

&

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.