UNIX
© Copyright B. Brown, 1988-2000. All rights reserved. March 2000.
Previous Page Index Next Page

Assignment 2a: An Introduction to mail


mail permits people on UNIX systems to send each other messages, transfer small files, act as personal reminders and communicate with people on remote systems.


MailBoxes
UNIX uses two mailboxes to hold mail messages

	system mailbox (/usr/spool/mail/)
	user mail box (..../.../mbox)

Mail arrives in the system mailbox, and is saved in your user mail box after you have read it. The user mail box is normally located in their $HOME directory.


The Format Of Mail Messages
A mail message is exchanged between people. Mail messages consist of two parts

	header		contains information about sender, receiver and subject
	body		actual content of message


Mail Headers
Mail headers have the following construction


	To:		This specifies the name of the recipients of the message (mandatory)
	Subject:	Title describing the message (optional)
	Cc:		List of people to receive a carbon copy (optional)
	Bcc:		List of people to receive blind carbon copy (they do not see user names in the received message. Optional)


Modes Of Operation For The mail Program
The mail program operates in two main modes

	compose mode	messages are created
	command mode	manage your mail, list/edit/delete/print/save messages

Typing the command mail runs the mail program and checks for mail. If there is mail, command mode is entered. If there is no mail, the program returns immediately.

Compose mode is entered when you invoke the mail program and specify a user as an argument, eg.

	mail  username


Entering mail Compose Mode
This mode is entered by invoking the mail program from the UNIX command line prompt and specifying a user to which the mail should be sent.

The example below invokes the mail program and names the recipient of the message as joe. The user is placed into compose mode, where the message contents is filled in (DO NOT type this example!).

	mail  joe

In order for you to become familiar with the features of mail, run the mail program as show above, BUT, use your login name instead of the user joe.

This means the mail will be sent to yourself. This is the best way to learn all the features of mail, without distracting other people.

TYPE

	mail  your_user_name

(where your_user_name is the login name you used to login to the UNIX host).


When the mail program starts, it reads a mail script file (if one is present) located in the user home directory. This specifies options for how the mail program works.

One of the options is asksub, which tells the mail program to ask for a subject heading. If this option is set, then the mail program prompts you to enter a subject line,

	Subject:

Enter the string "My first message" as the subject content for this message. Subject fields are limited to a single line.

The mail program is now in compose mode. Enter each of the following lines. At the end of each line press .

	This is my first UNIX mail message.
	I am entering the contents of this message in compose mode.
	Once I press the return key I cannot edit previous lines
	Have a nice day

Note:

	To delete a line in compose mode, press CTRL-U
	To view the message before sending it, press ~p
	To abort the message, press the DELETE key twice
		(this has been mapped to CTRL-BS on the IBM-PC keyboard, and 
		 will save the message in the file dead.letter)
	To send the message, press CTRL-d

To finish entering the message, press CTRL-d. The mail message is sent, and the mail program returns you to the shell prompt.


Sending a mail message contained in a file to a user
If the mail message already exists in a file, this is sent to a user by typing the following command (its an example, do not type it),

	mail  joe  <  message

which sends the text file message to the user joe.


1: Create a file name "tmpfile" which contains a message to send.

	cat  -  >  tmpfile
	Hello and welcome. This message was in
	a file named tmpfile.

2: Send the file to yourself as outlined above.

	mail  your_user_name  <  tmpfile


Specifying the Subject Content when sending a message
The command line option -s specifies the subject header for mail to use. The following command

	mail  -s  "Meeting today at 11:00am"   joe   <   message

sends the file message to the user joe and inserts the text string "Meet...am" into the subject field of the message header.

Send the file "tmpfile" to yourself, using a subject header string "My message3"


Entering mail command mode
This mode is entered when you invoke the mail program without arguments and there is mail waiting for you.

Type

	mail

The mail program displays a title message and lists all available mail headers,

SCO System V Mail (version 3.2)  Type ? for help.
"/usr/spool/mail/brianb": 3 messages 3 new
 N  3 brianb	Mon May 31 15:02   10/299   My message3
 N  2 brianb	Mon May 31 15:01    9/278
>N  1 brianb	Mon May 31 15:00   12/415   My first message
&

This initial screen displays the subject fields of messages which have arrived. The format of the display is,

	Type	Message_number		From_User	Date/Time	Subject

	N	denotes a new message
	>	denotes the current message
	&	mail prompt symbol
		

Note how message number 2 does not have a subject heading. This is because the mail message was sent from a file, and the -s option was not specified on the command line when the mail program was invoked.


Getting help
To display help whilst running the mail program, type a question (?) mark


type [msglist]		print messages
next			goto and type next message
edit [msglist]		edit messages
from [msglist]		give header lines of messages
delete [msglist]	delete messages
undelete [msglist]	restore deleted messages
save [msglist] file	append messages to file
reply [message]		reply to message, including all recipients
Reply [msglist]		reply to the authors of the messages
preserve [msglist]	preserve messages in mailbox
mail user		mail to specific user
quit			quit, preserving unread messages
xit			quit, preserving all messages
header			print page of active message headers
!			shell escape
cd [directory]		chdir to directory or home if none given
list			list all commands (no explanations)
top [msglist]		print top 5 lines of messages
z [-]			display next [last] page of 10 headers

[msglist] is optional and specifies messages by number, author, subject or type.  The default is the current message.



Reading the current message
To read the current message denoted by the > symbol, press the return key. The mailer displays the message as follows,

Message  1:
From brianb Mon May 31 15:00:20 1993
From: brianb@cit1.cit.ac.nz (Brian Brown)
X-Mailer: SCO System V Mail (version 3.2)
To: brianb
Subject: My first message
Date: Mon, 31 May 93 15:00:16 NZT
Message-ID:  <9305311500.aa12036@cit1.cit.ac.nz>
Status: RO

This is my first UNIX mail message.
I am entering the contents of this message in compose mode.
Once I press the return key I cannot edit previous lines
Have a nice day

Read messages are not held in the system mailbox when you exit the mail program.

If you want to save these messages after reading them, you must do so before exiting the mail program.

To read the next message, press the return key. The mailer responds with

Message  2:
From brianb Mon May 31 15:01:48 1993
From: brianb@cit1.cit.ac.nz (Brian Brown)
X-Mailer: SCO System V Mail (version 3.2)
To: brianb
Date: Mon, 31 May 93 15:01:47 NZT
Message-ID:  <9305311501.aa12046@cit1.cit.ac.nz>
Status: R

Hello and welcome. This message was in
a file named tmpfile.


Using the 'header' command to view mail headers
The header command in compose mode lists the headers of all mail messages. The message header contains,

	N if the message is new
	the message number (1, 2, 3.. n)
	the username of the sender
	the date and time of arrival
	the number of lines/the number of bytes in the message
	the subject field contents

Type the header command to list the available messages. Your display should now look like,

& header
 N  3 brianb	Tue Jun  1 08:43   10/308   My message3
>   2 brianb	Tue Jun  1 08:42    9/287
    1 brianb	Tue Jun  1 08:41   12/417   My first message
&


Reading Specific Messages Using The type Command
The type command in compose mode is used to view specific messages. As an argument, it accepts, the message number or senders name. If no argument is given, it displays the current selected message denoted by the symbol >.


	Examples
	type  1			types message 1
	type  jim		types the message from user jim
	type			type the current highlighted message

Type the command type without arguments.

Which message number was printed out?..................................................


Printing a mail message
The l command prints a specified mail message. The following command prints all mail messages received from the user joe.

	l   joe

To print the current message, do not supply any arguments. Print the current message and attach it to this booklet for assessment.


Saving a mail message
The hold or preserve command saves the message in the system mail box. This means it will still be visible next time you enter mail.

Leaving mail with the quit command normally saves the message in the persons mailbox. It will not appear in the list of mail messages next time the mail program is invoked.

Type the command hold to preserve the current message. Follow this command by using the header command to display the message headers. Your screen should look like,

& hold
& header
N    3 brianb           Tue Jun  1 08:43   10/308   My message3
>P  2 brianb           Tue Jun  1 08:42    9/287
       1 brianb           Tue Jun  1 08:41   12/417   My first message
&

Note how the P symbol highlights the message as being Preserved. This message will be available next time you run the mail program, as well as un-read messages, but the messages that you have read will not be available.


Saving the current mail message to a file
People will generally save important messages in a file. This is done by using the save command and specifying a file to save the message in,

	s  meetings

saves the current message in the file meetings. This file is now treated as a mail folder by the mail program. The command

	s  1  welcome

saves message number 1 in a mail folder named welcome.

Save message 3 to a file name "message1"


Deleting the current message
The delete command deletes messages.

	examples
	delete  joe		delete the message from user joe
	delete  1		delete message number 1


Replying to a mail message
The reply command allows you to send a reply to the sender of the message.

	examples
	reply 	2		reply to message number 2
	reply			reply to the current message

If the original message contains a subject field, the mailer will automatically fill this in for you, taking the contents of the original messages subject field.


Forwarding a mail message
A message is forwarded (sent on to) another user by using the forward command.

	examples
	f  1  brianb		forward message number 1 to user brianb
	f  2  brianb  joe  	forward message number 2 to brianb and joe


Working in Compose Mode
In compose mode, the mail program accepts special key sequences. These commands begin with the tidle (~) symbol. You will note that if you make a mistake on a previous line, you cannot go back and change it (at least not yet).

Using the command sequence ~v invokes the UNIX editor vi, and permits you to edit the message you have entered. After exiting vi, you are back into mail compose mode, where you continue entering lines or send the message by pressing ctrl-d.

To display a list of available escape sequences, enter the following command whilst in compose mode.

	~?

To list previous entered lines whilst in compose mode, press ~p

You can abort the sending of a message by pressing the interrupt key (either BACKSPACE or CTRL-BACKSPACE) twice. If you abort a message in this manner, the message is saved in the file dead.letter in your $HOME directory.


Using different mail folders
When the mail program starts, it uses the default mail folder, which is the system mailbox. Remember the save mail message command, which saved the mail message to a file.

It was stated that the mail program treats this file as a mail folder.

By specifying the mail folder on the command line as an argument, mail will use a different mail folder.

	mail  -f  meetings 


Executing shell commands
UNIX commands are executed from within the mailer by preceding them with an exclamation symbol

	examples
	!ls -la		do a directory listing
	!sh		run a shell


Sending Mail To People At Other Host Machines Or Sites
You send mail to other people at remote sites by specifying their specific mail address.

	examples
	brian@brian.cit.ac.nz
	os2user@brian.cit.ac.nz
	your_user_name@csc.cit.ac.nz

You can practise this by sending mail to yourself. As a student at CIT, you have an account on one of the student Netware servers. This is connected to the mail system of the CIT UNIX host, cit1. Your mail address is thus,

	your_user_name@server_name.cit.ac.nz

For instance, if your username was huntsam, and the Netware server name was CC2, then your mail address is

	huntsam@cc2.cit.ac.nz

Send yourself a mail message to your account.

Note: This only works if you have been enabled with INTERNET access!


Previous Page Index Next Page