Chapter 7

Mail

Introduction

In this chapter, we briefly examine Unix's facilities for sending messages to other users of our system. The same command is used for users of other systems but the messages are routed via the internet.

Reading mail

Unix originally had at least two mail commands; the most commonly used is mailx. Another, more basic command, is usually available under the name mail. This is available on Linux whereas mailx isn't.

The simplest use for either command is checking whether anyone has sent me any mail:

$ mailx
No mail for cmsps
$ mail
No mail.
$

As you see, the commands have slightly different ways of saying the same thing. The cmsps used by mailx is my Unix login code

I can solve the problem of having no mail by sending myself some:

$ mailx cmsps
Subject: Good news
I love you.
I love you.
I love you.
.
EOT
$

The login code argument tells mailx that we are sending rather than reading mail. Notice that Subject: is a prompt and that mailx expects the first line typed by the user after the command line to be the subject of the message. All lines after that make up the text of the message. The line containing just a full stop indicates the end of the text and mailx displays EOT accordingly.

We generally store messages in files and then use Unix's input redirection facility to send them

$ mailx -s 'Bad news' cmsps < hatemail
$

The -s option is followed by the subject of the message.

We are now ready to read these two messages:

$ mailx
mailx version 5.0 Thu May  2 21:00:21 PDT 1996  Type ? for help.
"/var/mail/cmsps": 2 messages 2 new
>N  1 Peter Scott        Thu Feb 27 15:41   13/341   Good news
 N  2 Peter Scott        Thu Feb 27 15:42   13/348   Bad news
? p1
Message  1:
From cmsps Thu Feb 27 15:41:05 1997
Date: Thu, 27 Feb 1997 15:41:03 GMT
From: Peter Scott <cmsps>
To: cmsps
Subject: Good news

I love you.
I love you.
I love you.

? d1
? h
>N  2 Peter Scott        Thu Feb 27 15:42   13/348   Bad news
? p2
Message  2:
From cmsps Thu Feb 27 15:42:29 1997
Date: Thu, 27 Feb 1997 15:42:26 GMT
From: Peter Scott <cmsps>
To: cmsps
Subject: Bad news

You hate me.

? d2
? h
No applicable messages
? q
$

Internet mail

$ mailx p.scott@shu.ac.uk
Subject: Unix Book
Hi Peter,

I love your book.

Peter.
.
EOT
$

Two useful commands

w file
?

Two mail-boxes

Users have two mail boxes. Mine are:

/var/mail/cmsps           -- in the public, shared space
/homedir/cms/ps/mbox      -- in my private space

The idea is that new mail is stored in the public, shared space and the user is notified about its arrival. When the user reads the mail but does not delete it, it is then moved into the user's private space. The -f option tells mailx to use the other mailbox.

$ mailx -f
/homedir/cms/ps/mbox: No such file or directory
$

I have no old, undeleted mail so there isn't a mailbox. In common with most mail handlers, mailx deletes the mailbox when it's empty.

Extra mail boxes

If we supply the name of another mail box file, mailx tries to use it:

$ mailx -f extra
extra: No such file or directory
$

Other mail handlers

Neither mailx nor mail can deal with attachments. The simplest mail handler that allows attachments is Alpine; it is a full-screen mail handler in the sense that vi is a full-screen editor. Consequently, it only works in xterm's.

QUESTIONS

  1. pending

  2. pending

ANSWERS

  1. pending

  2. pending