|Purchase||Copyright © 2002 Paul Sheer. Click here for copying permissions.||Home|
Electronic Mail, or email, is the way most people first come into contact with the Internet. Although you may have used email in a graphical environment, here we show you how mail was first intended to be used on a multiuser system. To a large extent what applies here is really what is going on in the background of any system that supports mail.
A mail message is a block of text sent from one user to another, using some mail command or mailer program. A mail message will usually also be accompanied by a subject explaining what the mail is about. The idea of mail is that a message can be sent to someone even though he may not be logged in at the time and the mail will be stored for him until he is around to read it. An email address is probably familiar to you, for example: email@example.com. This means that bruce has a user account on a computer called kangeroo.co.au, which often means that he can log in as bruce on that machine. The text after the @ is always the name of the machine. Today's Internet does not obey this exactly, but there is always a machine that bruce does have an account on where mail is eventually sent. [That machine is also usually a UNIX machine.]
Sometimes email addresses are written in a more user-friendly form like Bruce Wallaby <firstname.lastname@example.org> or email@example.com (Bruce Wallaby). In this case, the surrounding characters are purely cosmetic; only firstname.lastname@example.org is ever used.
When mail is received for you (from another user on the system or from a user from another system) it is appended to the file /var/spool/mail/<username> called the mail file or mailbox file; <username> is your login name. You then run some program that interprets your mail file, allowing you to browse the file as a sequence of mail messages and read and reply to them.
An actual addition to your mail file might look like this:
Each mail message begins with a From at the beginning of a line, followed by a space. Then comes the mail header, explaining where the message was routed from to get to your mailbox, who sent the message, where replies should go, the subject of the mail, and various other mail header fields. Above, the header is longer than the mail messages. Examine the header carefully.
The header ends with the first blank line. The message itself (or body) starts right after. The next header in the file will once again start with a From. Froms on the beginning of a line never exist within the body. If they do, the mailbox is considered to be corrupt.
Some mail readers store their messages in a different format. However the above format (called the mbox format) is the most common for UNIX. Of interest is a format called Maildir, which is one format that does not store mail messages in a single contiguous file. Instead, Maildir stores each message as a separate file within a directory. The name of the directory is then considered to be the mailbox ``file''; by default Maildir uses a directory Maildir within the user's home directory.
The simplest way to send mail is to use the mail command. Type mail -s "hello there" <username>. The mail program will then wait for you to type out your message. When you are finished, enter a . on its own on a single line. The user name will be another user on your system. If no one else is on your system, then send mail to root with mail -s "Hello there" root or mail -s "Hello there" root@localhost (if the @ is not present, then the local machine, localhost, is implied). Sending files over email is discussed in Section 12.6.
You can use mail to view your mailbox. This is a primitive utility in comparison with modern graphical mail readers but is probably the only mail reader that can handle arbitrarily sized mailboxes. Sometimes you may get a mailbox that is over a gigabyte in size, and mail is the only way to delete messages from it. To view your mailbox, type mail, and then z to read your next window of messages, and z- to view the previous window. Most commands work like command message_number, for example, delete 14 or reply 7. The message number is the left column with an N next to it (for a New message).
For the state of the art in terminal-based mail readers (also called mail clients), try mutt and pine. [ pine's license is not Free.]
There are also some graphical mail readers in various stages of development. At the time I am writing this, I have been using balsa for a few months, which was the best mail reader I could find.
To send mail, you need not use a mail client at all. The mail client just follows SMTP (Simple Mail Transfer Protocol), which you can type in from the keyboard.
For example, you can send mail by telneting to port 25 of a machine that has an MTA (Mail Transfer Agent--also called the mailer daemon or mail server) running. The word daemon denotes programs that run silently without user intervention.
This is, in fact, how so-called anonymous mail or spam mail [Spam is a term used to indicate unsolicited email--that is, junk mail that is posted in bulk to large numbers of arbitrary email addresses. Sending spam is considered unethical Internet practice.] is sent on the Internet. A mailer daemon runs in most small institutions in the world and has the simple task of receiving mail requests and relaying them on to other mail servers. Try this, for example (obviously substituting mail.cranzgot.co.za for the name of a mail server that you normally use):
The above causes the message `` hi there heres a short message'' to be delivered to email@example.com (the Re Ci Pien T). Of course, I can enter any address that I like as the sender, and it can be difficult to determine who sent the message. In this example, the Subject: is the only header field, although I needn't have supplied a header at all.
Now, you may have tried this and gotten a rude error message. This might be because the MTA is configured not to relay mail except from specific trusted machines--say, only those machines within that organization. In this way anonymous email is prevented.
On the other hand, if you are connecting to the user's very own mail server, it has to necessarily receive the mail, regardless of who sent it. Hence, the above is a useful way to supply a bogus FROM address and thereby send mail almost anonymously. By ``almost'' I mean that the mail server would still have logged the machine from which you connected and the time of connection--there is no perfect anonymity for properly configured mail servers.
The above technique is often the only way to properly test a mail server, and should be practiced for later.