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.
Unix originally had at least two mail commands; the most commonly used is
Another, more basic command, is usually available under the name
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
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
that we are sending rather than reading mail.
is a prompt and that
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
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 $
$ mailx firstname.lastname@example.org Subject: Unix Book Hi Peter, I love your book. Peter. . EOT $
w file ?
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.
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,
deletes the mailbox when it's empty.
If we supply the name of another mail box file,
tries to use it:
$ mailx -f extra extra: No such file or directory $
it is a full-screen mail handler in the sense that
is a full-screen editor.
Consequently, it only works in