Using Email
BSD has local email support out of the box.. (FreeBSD 5.4)
Posted 23.04.2006 | Updated 23.05.2006 | Contributed by Andy Mallett



Amongst its many quirks, Unix uses email as a way of alerting users to some system events.

Specifically the root user will get email events from the system when something of significance happens.

Unix users can also send each other messages via the inbuilt email system.

Here's what you can and can't do..
  • Users can send emails to other user accounts on the same server. Users check these emails by logging into the server directly or through an SSH session. More on this shortly.
  • Users can also pull their FreeBSD emails from another workstation using IMAP
  • You cannot send email from your FreeBSD server to another server, without extra configuration (see SMS and Email Out). FreeBSD's own Sendmail is intentionally locked down to only local emails by default, to prevent Unix boxes becoming unwitting spam relayers.
The purpose of this article is to explain how to use the local email facility.

Basic Mail Usage

Unix email is a very basic no-frills mail system which is of course, command driven.

 To check your mail, type the mail command..

su-2.05b# mail
You have new mail in /var/mail/andym
su-2.05b# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/andym": 5 messages 5 new
>N  1 andym@vamp.playroom Sat Apr 22 09:54  18/669 "Test Message"
 N  2 andym@vamp.playroom Sun Apr 23 21:54  18/665 "Andy, you are sexy.."
 N  3 andym@vamp.playroom Mon Apr 24 08:54  18/667 "I was  a bit drunk.."
&
& q
su-2.05b#


Note that the command prompt changes to the & symbol to show you're in 'email' mode. Any mail will be listed with a sequential number next to it. Type the number and press ENTER to read that message. Scroll through with the usual arrow keys. To exit the email prompt, type q (for quit) and press ENTER. You are returned to the usual command prompt.

By default, all messages are held in the /var/mail directory. Each user's email messages are stuffed into a single file, with the same filename as the user account. So for user andym, all his messages live in the file /var/mail/andym. Root's emails are kept in /var/mail/root, and so on.


 To send an email, type the mail username command..

su-2.05b# mail andym
Subject: This is the subject line
This is the message
EOT
su-2.05b#


You get prompted for the subject line and the message. To send the completed masterpiece, type CTRL d. After sending, this chucks you out of the email prompt and back to the standard command prompt.

Note that the /var/mail/username file is a clear text file and like any text file under Unix, it is editable with a text editor. Edit it, delete it, whatever. When a new message arrives, a new file for that username will be created.

Hate command line email? Try Pine..