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..
You have new mail in /var/mail/andym
Mail version 8.1 6/6/93. Type ? for help.
"/var/mail/andym": 5 messages 5 new
>N 1 email@example.com Sat Apr 22 09:54 18/669 "Test Message"
N 2 firstname.lastname@example.org Sun Apr 23 21:54 18/665 "Andy, you are sexy.."
N 3 email@example.com Mon Apr 24 08:54 18/667 "I was a bit drunk.."
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
su-2.05b# mail andym
Subject: This is the subject line
This is the message
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