Previous Up Next

8  Email and Unix

8.1  A general overview of email under Unix

Email under Unix is not just a large black box whereby mail flows magically into a mailbox, but its a definite part of the system and is broken down into a number of sections. A rough diagram of how mail gets into your mailbox is as follows:

Network --> MTA --> MDA --> Your inbox

Where “Network” represents any form of outside machine that could be sending you mail. MTA stands for “Mail Transport Agent”, normally an SMTP server like sendmail or exim running on the Unix machine. The MTA is responsible for transporting mail between machines. MDA stands for “Mail Delivery Agent” this is a program responsible for delivering mail which is addressed to you from the machines MTA to your Inbox.

Sending mail works similarly, and a rough map is below:

MUA --> MTA --> Network

Here MUA is your “Mail User Agent”, basically a mail client, that hands off to the MTA (see above) which if the mail is destined for a remote host sends it off over the network. If however the mail is for another user on the local machine the MTA hands it to the MDA and that delivers it to the user’s mailbox.

Now before I get into discussing which parts of these systems you need to know about there will be a short description of what an email address really is. Consider the example below (Nb: there isn’t a Unix machine at melody.lancs.ac.uk, this is used purely for example):

frank@melody.lancs.ac.uk

Now essentially what this means in terms of Unix systems is that there is an account called “frank” on the machine at “melody.lancs.ac.uk”, and when mail arrives at melody.lancs.ac.uk addressed to frank the MTA hands it to the MDA and it’s put in his inbox, simple as that.

8.2  Forwarding Email

If you want to forward the email from your Lancaster Account (please don’t, forwards do occasionally break through no fault of the University and wind up bouncing) then its fairly simple to do.

You can either use the “Management” option for your account after logging into the Wing system (http://wing.lancs.ac.uk) or you can use a .forward file.

To change your forward at the Unix prompt simply use the following command:

% echo "forward@domain.tld" > $MAILHOME/.forward

And replace “forward@domain.tld” with the address you wish mail to be fowarded to.

8.3  Mail User Agent

The choice that will most affect your experience of Unix MUA (“Mail User Agent”), like the Editors section (see section 5) there are several popular MUAs that will be discussed in this section, and all of them are simple textual applications. While there are many graphical mail clients for Unix this document is an introduction to shell accounts, so I won’t be dealing with any of them.

Historically the standard mail client for reading mail with on Unix systems was “mail”. However this is not a very powerful or user friendly MUA and so its use is discouraged, however it is available if you wish to look at it. Documentation for mail (and the newer version “mailx” is available from “man mail” as ever.

The supported MUA for the University Unix systems is a program called “elm”. It is more advanced than mail and offers far more options as well as user friendliness to its users, this document includes a short section on elm.

Elm is documented at: http://hedgehog.lancs.ac.uk:8080/mail/ and also in “man elm”.

There are also two more MUA’s installed on cent1, these are mutt and pine. It’s worth noting that these MUA’s are part of the homegrown package (see section 13.1) and thus there is no official support for them, so if you misconfigure them and manage to lose mail then you probably won’t get any help. However they offer a much better user experience for reading and writing email.

8.3.1  mutt

mutt is a fairly simple to use MUA, said to combine the best features of elm and pine. This will only be a brief introduction but full information is available via “man mutt” and http://www.mutt.org/

In its default configuration it will display a line at the top of the screen listing various options (including ‘q’ for quit and ‘?’ for help). Pressing any of those will perform that action. The status bar at the bottom of the screen displays information about your mailbox (messages count, new message count, size of the mailbox etc). The cursor keys should move you up and down the list of messages in your inbox, failing that ‘j’ will move down and ‘k’ will move up. If you press the space bar on a message you can read it, it’ll open in a pager much like “less”, and the top bar will display the keys that affect it (‘i’ to go back to the message view, ‘-’ (dash) to go back a page, space bar for next page etc.).

Mutt is well liked by many people, it can be made quite simply to use colours to highlight certain messages (like new ones), display a threaded view of your messages in part of the screen and the rest of the message in another, and by default it uses your $VISUAL variable for the message editor. It also has many more features, www.mutt.org contains a list.

Mutt is started simply with the command:

% mutt 

8.3.2  pine

The other main console mail tool is pine (a “Program for Internet News & Email”), it too is fairly simple to use, and is fully documented at:
http://www.washington.edu/pine/

When you first start pine you will get a brief introductory message telling you about it, the bottom of the screen will include the various options you can do with key-strokes, the letter in question in bold. So press ‘e’ to leave the greeting.

After that you will be at Pine’s main menu, this is what you will see every other time you start it, and will allow you to view the list of messages or a current message, or write a new one. There is also a “setup” menu here, available from the letter ‘s’, this will take you through a series of menus to define how you want Pine to be configured without having to touch its configuration file by hand.

Pine is started with the very simple command:

% pine 

Its worth noting that in its default state Pine uses pico (see 5.4) for its default editor, and even if your have $VISUAL set will ignore it. To make it use your choice of editor you need to press ‘s’ from its main-menu for the setup, then look for the alternative-editor options.

Alternatively edit the ~/.pinerc file and add (or change) the line that reads “editor=” putting the name of your editor after the ‘=’ (equals) symbol. Then when you’ve typed in the To: and Subject: fields of your message in pine press ^_ (control and ‘_’ (underscore)) to start the editor.

8.4  fetchmail

fetchmail is a program that has an apparently simple task, to fetch your email from a remote mail server and deliver it to the local one so that it can be delivered to your inbox (see section 8) as normal. Before writing a description of fetchmail it is worth noting that it is installed as part of the “homegrown” section of cent1 (see 13.1) and subject to all the normal restrictions about support i.e. there isn’t any officially and if you misconfigure it and it goes wrong you might get in trouble. It’s worth repeating this especially for fetchmail as misconfiguring it can lead to very noisy mail bounces.

Anyway, fetchmail is fully documented at:
http://catb.org/~esr/fetchmail/

Fetchmail is controlled by a “~/.fetchmailrc” file, for a start this must have the permissions set so that only your user can read it (see section 4.8). A template configuration file which has been commented is available from section 14.

8.5  procmail, your MDA

The MDA on the system is a program called procmail. Procmail is a general purpose program that can filter mail based on an amazing number of criteria, sorting it into various mailboxes, and do virtually anything, even trigger other programs, on incoming email. However searching for procmail on cent1 won’t actually find it, as all the real email processing is handled by several other machines. However, procmail is installed on them.

Since procmail isn’t even installed on the machine, much less homegrown, no support is offered for it, and since mistakes in its configuration can make it silently destroy all incoming email (in many amusing ways) or forward it to a scammer in outer Mongolia it’s worth being very careful about configuring it.

This document will not teach you how to use procmail, as the subject is just too complex, this is just a note to let adventurous users know it’s installed. Anyone wanting to know more is encouraged to read http://www.procmail.org/ and send test mails to be sure of your config.

As a last point if you create a “.procmailrc” file in your home directory then fairly soon (about every hour) a cronjob (see section 12.7.1) will run, moving it over to the correct place on the Mail servers for it to take effect, if this is too slow for you then use of the $MAILHOME variable should prove enlightening (again, be very careful with procmail, it is not supported and is complex).


Previous Up Next