Handling Email - Ubuntu as a Server - Ubuntu Unleashed 2017 Edition (2017)

Ubuntu Unleashed 2017 Edition (2017)

Part IV: Ubuntu as a Server

Chapter 28. Handling Email


In This Chapter

Image How Email Is Sent and Received

Image Basic Postfix Configuration and Operation

Image Using Fetchmail to Retrieve Mail

Image Choosing a Mail Delivery Agent

Image Alternatives to Microsoft Exchange Server

Image References


Email is still the dominant form of communication over the Internet. It is fast, free, and easy to use. However, much of what goes on behind the scenes is extremely complicated and would appear scary to anyone who does not know much about how email is handled. Ubuntu comes equipped with a number of powerful applications that will help you build anything from a small email server, right through to large servers able to handle thousands of messages.

This chapter shows you how to configure Ubuntu to act as an email server. We look at the options available in Ubuntu and examine the pros and cons of each one. You also learn how mail is handled in Linux and, to a lesser extent, in UNIX.

How Email Is Sent and Received

Email is transmitted as plain text across networks around the world using the Simple Mail Transfer Protocol (SMTP). As the name implies, the protocol itself is fairly basic, and it has been extended to add further authentication and error reporting/messaging to satisfy the growing demands of modern email. Mail transfer agents (MTAs) work in the background transferring email from server to server, allowing emails to be sent all over the world. You might have come across such MTA software such as Sendmail, Postfix, Fetchmail, Exim, or Qmail.

SMTP allows each computer that the email passes through to forward it in the right direction to the final destination. When you consider the millions of email servers across the world, you have to marvel at how simple it all seems.

Here is a simplified example of how email is successfully processed and sent to its destination:

1. matthew@seymourcray.net composes and sends an email message to heather@gracehopper.net.

2. The MTA at seymourcray.net receives Matthew’s email message and queues it for delivery behind any other messages that are also waiting to go out.

3. The MTA at seymourcray.net contacts the MTA at gracehopper.net on port 24. After gracehopper.net acknowledges the connection, the MTA at seymourcray.net sends the mail message. After gracehopper.net accepts and acknowledges receipt of the message, the connection is closed.

4. The MTA at gracehopper.net places the mail message into Heather’s incoming mailbox; Heather is notified that she has new mail the next time she logs on.

However, several things can go wrong during this process. Here are a few examples:

Image What if Heather does not exist at gracehopper.net? In this case, the MTA at gracehopper.net rejects the email and notifies the MTA at seymourcray.net of what the problem is. The MTA at seymourcray.net then generates an email message and sends it to matthew@seymourcray.net, informing him that no Heather exists at gracehopper.net (or perhaps just silently discards the message and gives the sender no indication of the problem, depending on how the email server is configured).

Image What happens if gracehopper.net doesn’t respond to seymourcray.net’s connection attempts? (Perhaps the server is down for maintenance.) The MTA at seymourcray.net notifies the sender that the initial delivery attempt has failed. Further attempts will be made at intervals decided by the server administrator until the deadline is reached, and the sender will be notified that the mail is undeliverable.

The Mail Transport Agent

Several MTAs are available for Ubuntu, each with its pros and cons. Normally they are hidden under the skin of Ubuntu, silently moving mail between servers all over the world with need for little or no maintenance. Some MTAs are extremely powerful, being able to cope with hundreds of thousands of messages each day, whereas some are geared more toward smaller installations. Other MTAs are perhaps not as powerful but are packed full with features. In the next section, we take a look at some of the more popular MTAs available for Ubuntu.

Sendmail

Sendmail handles the overwhelming majority of emails transmitted over the Internet today. It is extremely popular across the Linux/UNIX/BSD world and is well supported. A commercial version is available that has a GUI interface for ease of configuration.

As well as being popular, Sendmail is particularly powerful compared to some of the other MTAs. However, it is not without its downsides, and you will find that other MTAs can handle more email per second in a larger environment. The other issue with Sendmail is that it can be extremely complicated to set it up exactly as you want it. A few books are available specifically for Sendmail, but the most popular one has more than a thousand pages, reflecting the complex nature of the Sendmail configuration.

We can be thankful, however, that the default configuration for Sendmail works fine for most basic installations out of the box, making further configurations unnecessary. Even if you want to use it as a basic email server, you only need to do some minor tweaks. The level of complexity associated with Sendmail often leads to system administrators replacing it with one of the other alternatives that is easier to configure.

Postfix

Postfix has its origins as the IBM Secure Mailer but was released to the community by IBM. Compared to Sendmail, it is much easier to administer and has a number of speed advantages. Postfix offers a pain-free replacement for Sendmail, and you are able to literally replace Sendmail with Postfix without the system breaking a sweat. In fact, the applications that rely on Sendmail automatically use Postfix instead and carry on working correctly (because Postfix uses a Sendmail wrapper, which deceives other programs into thinking that Postfix is Sendmail). This wrapper, or more correctly interface, makes switching to Postfix extremely easy if you are already running Sendmail. Postfix also happens to be the MTA of choice for Ubuntu, so it is this one that we spend more time on later in this chapter.

For enhanced security, many Postfix processes used to use the chroot facility (which restricts access to only specific parts of the file system) for improved security, and there are no setuid components in Postfix. In Ubuntu, a chroot configuration is no longer used and is, in fact, discouraged by the Postfix author. You can manually reconfigure Postfix to a chroot configuration, but that is no longer supported by Ubuntu.

If you are starting from scratch, Postfix is considered a better choice than Sendmail.

Qmail and Exim

Qmail is a direct competitor to Postfix but is not provided with Ubuntu. Qmail is designed to be easier to use than Sendmail, as well as faster and more secure. However, Qmail is not a drop-in replacement for Sendmail, so migrating an existing Sendmail installation to Qmail is not quite as simple as migrating from Sendmail to Postfix. Qmail is relatively easy to administer, and it integrates with a number of software add-ons, including web mail systems and POP3 servers. Qmail is available from www.qmail.org/.

Exim is yet another MTA, and it is available at www.exim.org/. Exim is considered faster and more secure than Sendmail or Postfix but is much different to configure than either of those. Exim and Qmail use the maildir format rather than mbox, so both are considered “NFS safe” (see the following sidebar).


MDIR Versus Mailbox

Qmail also introduced maildir, which is an alternative to the standard UNIX method of storing incoming mail. maildir is a more versatile system of handling incoming email, but it requires your email clients to be reconfigured, and it is not compatible with the traditional UNIX way of storing incoming mail. You will need to use mail programs that recognize the maildir format. (The modern programs do.)

The traditional mbox format keeps all mail assigned to a folder concatenated as a single file and maintains an index of individual emails. With maildir, each mail folder has three subfolders: /cur, /new, and /tmp. Each email is kept in a separate, unique file. If you are running a mail server for a large number of people, you should select a file system that can efficiently handle a large number of small files.

mbox does offer one major disadvantage. While you are accessing the monolithic mbox file that contains all your email, suppose that some type of corruption occurs, either to the file itself or to the index. Recovery from this problem can prove difficult. The mbox files are especially prone to problems if the files are being accessed over a network and can result in file corruption; one should avoid accessing mbox mail mounted over NFS, the Network File System, because file corruption can occur.

Depending on how you access your mail, maildir does permit the simultaneous access of maildir files by multiple applications; mbox does not.

The choice of a mail user agent (MUA), or email client, also affects your choice of mail directory format. For example, the pine program does not cache any directory information and must reread the mail directory any time it accesses it. If you are using pine, maildir is a poor choice. More-advanced email clients perform caching, so maildir might be a good choice, although the email client cache can get out of synchronization. It seems that no perfect choice exists.

Ubuntu provides you with mail alternatives that have both strong and weak points. Be aware of the differences among the alternatives and frequently reevaluate your selection to make certain that it is the best one for your circumstances.


Choosing an MTA

Other MTAs are available for use with Ubuntu, but those discussed in the previous sections are the most popular. Which one should you choose? That depends on what you need to do. Postfix’s main strengths are that it scales well and can handle large volumes of email at high speeds, not to mention that it is much easier to configure than the more cryptic Sendmail. However, you may find that there are specific things that you need that only Sendmail can provide. It is easy to switch between MTAs when you need to.

The Mail Delivery Agent

SMTP is a server-to-server protocol that was designed to deliver mail to systems that are always connected to the Internet. Dial-up systems connect only at the user’s command; they connect for specific operations, and are frequently disconnected. To accommodate this difference, many mail systems also include a mail delivery agent (MDA). The MDA transfers mail to systems without permanent Internet connections. The MDA is similar to an MTA (see the following note), but does not handle deliveries between systems and does not provide an interface to the user.


Note

Procmail or Spamassassin are examples of MDAs; both provide filtering services to the MDA while they store messages locally and then make them available to the MUA or email client for reading by the user.


The MDA uses the Post Office Protocol version 3 (POP3) or Internet Message Access Protocol (IMAP) for this process. In a manner similar to a post office box at the post office, POP3 and IMAP implement a “store and forward” process that alleviates the need to maintain a local mail server if all you want to do is read your mail. For example, dial-up Internet users can intermittently connect to their ISP’s mail server to retrieve mail using Fetchmail—the MDA recommended by Ubuntu (see the section “Using Fetchmail to Retrieve Mail” later in this chapter).

The Mail User Agent

The mail user agent (MUA) is another necessary part of the email system. The MUA is a mail client, or mail reader, that enables the user to read and compose email and provides the user interface. (It is the email application itself that most users are familiar with as “email.”) Some popular UNIX command-line MUAs are elm, pine, and mutt. Ubuntu also provides modern GUI MUAs: Evolution, Thunderbird, Mozilla Mail, Balsa, Sylpheed, and KMail. For comparison, common non-UNIX MUAs are Microsoft Outlook, Outlook Express, Pegasus Mail, and Apple Inc.’s Mail.

The Microsoft Windows and Macintosh MUAs often include some MTA functionality; UNIX does not. For example, Microsoft Outlook can connect to your Internet provider’s mail server to send messages. On the other hand, UNIX MUAs generally rely on an external MTA such as Sendmail. This might seem like a needlessly complicated way to do things, and it is if used to connect a single user to her ISP. For any other situation, however, using an external MTA allows you much greater flexibility because you can use any number of external programs to handle and process your email functions and customize the service. Having the process handled by different applications gives you great control over how you provide email service to users on your network, as well as to individual and small office/home office (SOHO) users.

For example, you could do the following:

Image Use Evolution to read and compose mail

Image Use Sendmail to send your mail

Image Use xbiff to notify you when you have new mail

Image Use Fetchmail to retrieve your mail from a remote mail server

Image Use Procmail to automatically sort your incoming mail based on sender, subject, or many other variables

Image Use Spamassassin to eliminate the unwanted messages before you read them

Basic Postfix Configuration and Operation

Because Postfix is the Ubuntu-recommended MTA, the following sections provide a brief explanation and examples for configuring and operating your email system. As mentioned earlier, however, Postfix is an extremely complex program with many configuration options. Therefore, this chapter only covers some of the basics.

Postfix is not installed by default. To use it, install the postfix package from the Ubuntu software repositories. During installation, you are asked a series of questions to help configure Postfix immediately. Research the settings for your situation before you start; some are merely preferential, but others are based on your hardware, network, and use case. You are asked the following:

Click here to view code image

General type of mail configuration: Internet Site

System mail name: mail.matthewhelmke.com
Root and postmaster mail recipient: <admin_user_name>
Other destinations for mail: mail.example.com, example.com, localhost.example.com,localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8

Mailbox size limit (bytes): 0
Local address extension character: +
Internet protocols to use: all

If you make a mistake and answer a configuration question incorrectly, you can go back through the process again by entering the following command from the command line:

Click here to view code image

matthew@seymour:~$ sudo dpkg-reconfigure postfix

Postfix configuration is maintained in files in the /etc/postfix directory with much of the configuration being handled by the file main.cf. You don’t have to use the preceding command to change these settings; you may do so by editing the appropriate files. The syntax of the configuration file, main.cf, is fairly easy to read (see the following example):

Click here to view code image

# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = optimus
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = optimus, localhost.localdomain, , localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

A useful command for configuring Postfix is postconf. It enables you to display and change many configuration settings without editing and saving configuration files. The command’s syntax is rather complex, but once learned it becomes a faster way to quickly adjust settings.

If you type the command by itself, it outputs a list of all configuration parameters. This can be quite long, so we recommend either sorting using a pipe and grep or sending the output to a file. See Chapter 11, “Command-Line Master Class Part 1,” for more on how to do this. This example shows the command piped into grep with a search for hostname:

Click here to view code image

matthew@seymour:~$ postconf | grep hostname
invalid_hostname_reject_code = 501
lmtp_lhlo_name = $myhostname
lmtp_tls_verify_cert_match = hostname
local_transport = local:$myhostname
milter_macro_daemon_name = $myhostname
myhostname = ubuntu
smtp_helo_name = $myhostname
smtp_tls_verify_cert_match = hostname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_proxy_ehlo = $myhostname
unknown_helo_hostname_tempfail_action = $reject_tempfail_action
unknown_hostname_reject_code = 450

To show the default parameter settings instead of the current settings, use this:

matthew@seymour:~$ postconf -d

Use this to discover which parameters have been changed from their defaults and display the current settings:

matthew@seymour:~$ postconf -n

Setting a parameter requires root privileges. For example, to set the myhostname parameter, use the following:

Click here to view code image

matthew@seymour:~$ sudo postconf -e "myhostname=mail.matthewhelmke.com"
myhostname=mail.matthewhelmke.com

This works with the parameters listed in the Postfix main.cf file:

Click here to view code image

matthew@seymour:~$ sudo postconf -e "smtp_sasl_auth_enable = yes"
myhostname=othername.matthewhelmke.com

As you can see, postconf is quite convenient. You can learn more about postconf from the man page.

You start, stop, and restart Postfix using this command, using the appropriate one of those three action words:

Click here to view code image

matthew@seymour:~$ sudo /etc/init.d/postfix start

Complicated email server setup is beyond the scope of this book; consider Postfix: The Definitive Guide, by Kyle Dent, for more information. This is a great reference and rather unusual because it is a complete and useful reference in only 250 pages or so. However, if you want to know something specific about Postfix, this is the book to read.

However, the following five sections address some commonly used advanced options. For more information on Postfix, as well as other MTAs, see the “References” section at the end of this chapter.

Configuring Masquerading

Sometimes you might want to have Postfix masquerade as a host other than the actual hostname of your system. Such a situation could occur if you have a dial-up connection to the Internet and your ISP handles all your mail for you. In this case, you want Postfix to masquerade as the domain name of your ISP. For example, the following strips any messages that come from matthew.gracehopper.net to just gracehopper.net:

Click here to view code image

masquerade_domains = gracehopper.net

Using Smart Hosts

If you do not have a full-time connection to the Internet, you will probably want to have Postfix send your messages to your ISP’s mail server and let it handle delivery for you. Without a full-time Internet connection, you could find it difficult to deliver messages to some locations (such as some underdeveloped areas of the world where email services are unreliable and sporadic). In those situations, you can configure Postfix to function as a smart host by passing email on to another sender instead of attempting to deliver the email directly. You can use a line such as the following in the main.cf file to enable a smart host:

relayhost = mail.isp.net

This line causes Postfix to pass any mail it receives to the server mail.isp.net rather than attempt to deliver it directly. Smart hosting will not work for you if your ISP blocks any mail relaying. Some ISPs block relaying because it is frequently used to disseminate spam.

Setting Message Delivery Intervals

As mentioned earlier, Postfix typically attempts to deliver messages as soon as it receives them, and again at regular intervals after that. If you have only periodic connections to the Internet, as with a dial-up connection, you likely would prefer Sendmail to hold all messages in the queue and attempt to deliver them whenever you connect to your ISP.

As dial-up connections have become the exception rather than the rule and are now quite rare, Ubuntu does not configure them by default and does not include the pppd daemon in the default installation. If you need this, install pppd from the Ubuntu software repositories. You can then configure Postfix to hold messages for later delivery by adding the following line to /etc/ppp/peers/ppp0:

/usr/sbin/sendmail -q

This line causes Postifix to automatically send all mail when connecting to your ISP.

However, Postfix still attempts to send mail regardless of whether the computer is on or off line, meaning that your computer may dial out just to send email. To disable this, you need to enter the following line into mail.cf:

defer_transports = smtp

This stops any unwanted telephone calls from being placed!


Tip

If you use networking over a modem, there is a configuration file for pppd called ppp0, which is located in /etc/ppp/peers. Any commands in this file automatically run each time the PPP daemon is started. You can add the line sendmail -q to this file to have your mail queue automatically processed each time you dial up your Internet connection.


Mail Relaying

By default, Postfix will not relay mail that did not originate from the local domain. This means that if a Postfix installation running at gracehopper.net receives mail intended for seymourcray.net, and that mail did not originate from gracehopper.net, the mail will be rejected and will not be relayed. If you want to allow selected domains to relay through you, add an entry for the domain to the main.cf file like this:

Click here to view code image

mynetworks = 192.168.2.0/24, 10.0.0.2/24, 127.0.0.0/8

The IP address needs to be specified in classless inter-domain routing (CIDR) format. For a handy calculator, head on over to www.subnet-calculator.com/cidr.php. You must restart Postfix for this change to take effect.


Caution

You need a good reason to relay mail; otherwise, do not do it. Allowing all domains to relay through you will make you a magnet for spammers who will use your mail server to send spam. This can lead to your site being blacklisted by many other sites, which then will not accept any mail from you or your site’s users—even if the mail is legitimate!


Forwarding Email with Aliases

Aliases allow you to have an infinite number of valid recipient addresses on your system, and you don’t have to worry about creating accounts or other support files for each address. For example, most systems have “postmaster” defined as a valid recipient but do not have an actual login account named postmaster. Aliases are configured in the file /etc/aliases. Here is an example of an alias entry:

postmaster: root

This entry forwards any mail received for postmaster to the root user. By default, almost all the aliases listed in the /etc/aliases file forward to root.


Caution

Reading email as root is a security hazard; a malicious email message can exploit an email client and cause it to execute arbitrary code as the user running the client. To avoid this danger, you can forward all of root’s mail to another account and read it from there. You can choose one of two ways for doing this.

You can add an entry to the /etc/aliases file that sends root’s mail to a different account. For example, root: foobar would forward all mail intended for root to the account foobar.

The other way is to create a file named .forward in root’s home directory that contains the address that the mail should forward to.


Any time you make a change to the /etc/aliases file, you must rebuild the aliases database before that change will take effect. Use the following command to do this:

Click here to view code image

matthew@seymour:~$ sudo newaliases

Using Fetchmail to Retrieve Mail

SMTP is designed to work with systems that have a full-time connection to the Internet. What if you are on a dial-up account? What if you have another system store your email for you and then you log in to pick it up once in a while? (Most users who are not setting up servers will be in this situation.) In this case, you cannot easily receive email using SMTP, and you need to use a protocol, such as POP3 or IMAP, instead.


Note

Remember when we said that some mail clients can include some MTA functionality? You can configure Microsoft Outlook and Outlook Express to use SMTP, and if you use a dial-up connection, they offer to start the connection and then use SMTP to send your mail, so a type of MTA functionality is included in those mail clients.


Unfortunately, many MUAs do not know anything about POP3 or IMAP. To eliminate that problem, you can use a program called Fetchmail to contact mail servers using POP3 or IMAP, download mail off the servers, and then inject those messages into the local MTA just as if they had come from a standard SMTP server. The following sections explain how to install, configure, and use the Fetchmail program.

Installing Fetchmail

Similar to other packages, you can install Fetchmail using either synaptic or apt-get.

You can get the latest version of Fetchmail at www.catb.org/~esr/fetchmail.

Configuring Fetchmail

After you have installed Fetchmail, you must create the file .fetchmailrc in your home directory, which provides the configuration for the Fetchmail program.

You can create and subsequently edit the .fetchmailrc file by using any text editor. The configuration file is straightforward and quite easy to create; the following sections explain the manual method for creating and editing the file. The information presented in the following sections does not discuss all the options available in the .fetchmailrc file, but covers the most common ones needed to get a basic Fetchmail installation up and running. You must use a text editor to create the file to include entries like the ones shown as examples—modified for your personal information, of course. For advanced configuration, see the man page for Fetchmail. The man page is well written and documents all the configuration options in detail.


Caution

The .fetchmailrc file is divided into three sections: global options, mail server options, and user options. It is important that these sections appear in the order listed. Do not add options to the wrong section. Putting options in the wrong place is one of the most common problems that new users make with Fetchmail configuration files.


Configuring Global Options

The first section of .fetchmailrc contains the global options. These options affect all the mail servers and user accounts that you list later in the configuration file. You can override some of these global options with local configuration options, as you learn later in this section. Here is an example of the options that might appear in the global section of the .fetchmailrc file:

set daemon 600
set postmaster foobar
set logfile ./.fetchmail.log

The first line in this example tells Fetchmail that it should start in daemon mode and check the mail servers for new mail every 600 seconds, or 10 minutes. Daemon mode means that after Fetchmail starts, it moves itself into the background and continues running. Without this line, Fetchmail checks for mail once when it started and then terminates and never checks again.

The second option tells Fetchmail to use the local account foobar as a last-resort address. In other words, any email that it receives and cannot deliver to a specified account should be sent to foobar.

The third line tells Fetchmail to log its activity to the file ./.fetchmail.log. Alternatively, you can use the line set syslog—in which case, Fetchmail logs through the syslog facility.

Configuring Mail Server Options

The second section of the .fetchmailrc file contains information on each of the mail servers that should be checked for new mail. Here is an example of what the mail section might look like:

poll mail.samplenet.org
proto pop3
no dns

The first line tells Fetchmail that it should check the mail server mail.samplenet.org at each poll interval that was set in the global options section (which was 600 seconds in our example). Alternatively, the first line can begin with skip. If a mail server line begins with skip, it will not be polled as the poll interval, but will only be polled when it is specifically specified on the Fetchmail command line.

The second line specifies the protocol that should be used when contacting the mail server. In this case, we are using POP3. Other legal options are IMAP, Authenticated Post Office Protocol (APOP), and Kerberized Post Office Protocol (KPOP). You can also use AUTO here, in which case Fetchmail attempts to automatically determine the correct protocol to use with the mail server.

The third line tells Fetchmail that it should not attempt to do a Dynamic Name Server (DNS) lookup. You probably want to include this option if you are running over a dial-up connection.

Configuring User Accounts

The third and final section of .fetchmailrc contains information about the user account on the server specified in the previous section. Here is an example:

user foobar
pass secretword
fetchall
no flush

The first line, of course, simply specifies the username that is used to log in to the email server, and the second line specifies the password for that user. Many security-conscious people cringe at the thought of putting clear-text passwords in a configuration file, and they should if it is group or world readable. The only protection for this information is to make certain that the file is readable only by the owner; that is, with file permissions of 600.

The third line tells Fetchmail that it should fetch all messages from the server, even if they have already been read.

The fourth line tells Fetchmail that it should delete the messages from the mail server after it has completed downloading them. This is the default, so we would not really have to specify this option. If you want to delete the messages from the server after downloading them, use the option flush.

The configuration options you just inserted configured the entire .fetchmailrc file to look like this:

Click here to view code image

set daemon 600
set postmaster foobar
set logfile ./.fetchmail.log

poll mail.samplenet.org
proto pop3
no dns

user foobar
pass secretword
fetchall
flush

This file tells Fetchmail to do the following:

Image Check the POP3 server mail.samplenet.org for new mail every 600 seconds.

Image Log in using the username foobar and the password secretword.

Image Download all messages off the server.

Image Delete the messages from the server after it has finished downloading them.

Image Send any mail it receives that cannot be delivered to a local user to the account foobar.

As mentioned earlier, many more options can be included in the .fetchmailrc file than are listed here. However, the options offered in this section will get you up and running with a basic configuration.

For additional flexibility, you can define multiple .fetchmailrc files to retrieve mail from different remote mail servers while using the same Linux user account. For example, you can define settings for your most often used account and save them in the default .fetchmailrc file. Mail can then quickly be retrieved like this:

Click here to view code image

matthew@seymour:~$ fetchmail -a
1 message for matthew at mail.matthewhelmke.com (1108 octets).
reading message 1 of 1 (1108 octets) . flushed

By using Fetchmail’s -f option, you can specify an alternative resource file and then easily retrieve mail from another server, as follows:

Click here to view code image

matthew@seymour:~$ fetchmail -f .myothermailrc
2 messages for matthew at matthew.helmke.com (5407 octets).
reading message 1 of 2 (3440 octets) ... flushed
reading message 2 of 2 (1967 octets) . flushed
You have new mail in /var/spool/mail/matthew

By using the -d option, along with a time interval (in seconds), you can use Fetchmail in its daemon, or background mode. The command launches as a background process and retrieves mail from a designated remote server at a specified interval. For more-advanced options, see the Fetchmail man page, which is well written and documents all options in detail.


Caution

Because the .fetchmailrc file contains your mail server password, it should be readable only by you. This means that it should be owned by you and should have permissions no greater than 600. Fetchmail complains and refuses to start if the .fetchmailrc file has permissions greater than this.


Choosing a Mail Delivery Agent

Because of the modular nature of mail handling, it is possible to use multiple applications to process mail and accomplish more than simply deliver it. Getting mail from the storage area and displaying it to the user is the purpose of the MDA. MDA functionality can be found in some of the mail clients (MUAs), which can cause some confusion to those still unfamiliar with the concept of UNIX mail. As an example, the Procmail MDA provides filtering based on rulesets; KMail and Evolution, both MUAs, provide filtering, but the MUAs pine, mutt, and Balsa do not. Some MDAs perform simple sorting, and other MDAs are designed to eliminate unwanted emails, such as spam and viruses.

You would choose an MDA based on what you want to do with your mail. We look at five MDAs that offer functions you might find useful in your particular situation. If you have simple needs (just organizing mail by rules), one of the MUAs that offers filtering might be better for your needs. Ubuntu provides the Evolution MUA as the default selection (and it contains some MDA functionality as previously noted), so try that first and see whether it meets your needs. If not, investigate one of the following MDAs provided by Ubuntu.

Unless otherwise noted, all the MDA software is provided in the Ubuntu repositories. Chapter 9, “Managing Software,” details the general installation of any software.

Procmail

As a tool for advanced users, the Procmail application acts as a filter for email, as it is retrieved from a mail server. It uses rulesets (known as recipes) as it reads each email message. No default configuration is provided; you must manually create a ~/.procmail file for each user, or users can create their own.

There is no system-wide default configuration file. The creation of the rulesets is not trivial and requires an understanding of the use of regular expressions that is beyond the scope of this chapter. Ubuntu does provide three examples of the files in /usr/share/doc/procmail/examples, as well as a fully commented example in the /usr/share/doc/procmail directory, which also contains a README and FAQ. You can find details for the rulesets in the man page for Procmail and in the man pages for procmailrc, procmailsc, and procmailex, which contain examples of Procmail recipes.

Spamassassin

If you have used email for any length of time, you have likely been subjected to spam, unwanted email sent to thousands of people at the same time. Ubuntu provides an MDA named Spamassassin to assist you in reducing and eliminating unwanted emails. Easily integrated with Procmail and Sendmail, it can be configured for both system-wide and individual use. It uses a combination of rule sets and blacklists (Internet domains known to mail spam).

Enabling Spamassassin is simple. You must first have installed and configured Procmail. The README file in /usr/share/doc/spamassasin provides details on configuring the .procmail file to process mail through Spamassassin. Spamassassin tags probable spam with a unique header; you can then have Procmail filter the mail in any manner you choose. One interesting use of Spamassasin is to use it to tag email received at special email accounts established solely for the purpose of attracting spam. This information is then shared with the Spamassassin site where these “spam trap”-generated hits help the authors fine-tune the rulesets.

Squirrelmail

Perhaps you do not want to read your mail in an MUA. If you use your web browser often, it might make sense to read and send your mail via a web interface, such as the one used by Gmail, Hotmail, or Yahoo! Mail. Ubuntu provides Squirrelmail for just that purpose. Squirrelmail is written in PHP and supports IMAP and SMTP. It supports MIME attachments and an address book and folders for segregating email.

You must configure your web server to work with PHP 4. You can find detailed installation instructions in /usr/share/doc/squirrelmail/INSTALL. After you configure Squirrelmail, point your web browser to the default install location, www.yourdomain.com/squirelmail/, to read and send email.

Virus Scanners

Although the currently held belief is that Linux is immune to email viruses targeted at Microsoft Outlook users, it certainly makes no sense for UNIX mail servers to permit infected email to be sent through them. Although Ubuntu does not provide a virus scanner by default, some of the more popular scanners are available in the Ubuntu repositories. Take a look at ClamAV as the most popular example.

Autoresponders

Autoresponders automatically generate replies to received messages; they are commonly used to notify others that the recipient is out of the office. Mercifully, Ubuntu does not include one by default, but you can find and install an autoresponder like vacation or gnarwl from the Ubuntu software repositories. If you are subscribed to a mailing list, be aware that automatic responses from your account can be very annoying to others on the list. Please unsubscribe from mail lists before you leave the office with your autoresponder activated.

Alternatives to Microsoft Exchange Server

One of the last areas in which a Microsoft product has yet to be usurped by open-source software is a replacement for Microsoft Exchange Server. Many businesses use Microsoft Outlook and Microsoft Exchange Server to access email and to provide calendaring, notes, file sharing, and other collaborative functions. General industry complaints about Exchange Server center around scalability, administration (backup and restore in particular), and licensing fees.

A “drop-in” alternative needs to have compatibility with Microsoft Outlook because it is intended to replace Exchange Server in an environment in which there are Microsoft desktops in existence using Outlook. A “work-alike” alternative provides similar features to Exchange Server but does not offer compatibility with the Microsoft Outlook client itself; the latter is typical of many of the open-source alternatives.

Several “drop-in” alternatives exist, none of which are fully open source because some type of proprietary connector is needed to provide the services to Microsoft Outlook clients (or provide Exchange services to the Linux Evolution client). For Outlook compatibility, the key seems to be the realization of a full, open implementation of MAPI, the Microsoft Messaging Application Program Interface. That goal is going to be difficult to achieve because MAPI is a poorly documented Microsoft protocol. For Linux-only solutions, the missing ingredient for many alternatives is a usable group calendaring/scheduling system similar in function to that provided by Exchange Server/Outlook.

Of course, independent applications for these functions abound in the open-source world, but one characteristic of “groupware” is its central administration; another is that all components can share information.

The following sections examine several of the available servers, beginning with Microsoft Exchange Server itself and moving toward those applications that have increasing incompatibility with it. None of these servers are provided with Ubuntu.

Microsoft Exchange Server/Outlook Client

Exchange Server and Outlook seem to be the industry benchmark because of their widespread deployment. They offer a proprietary server providing email, contacts, scheduling, public folders, task lists, journaling, and notes using Microsoft Outlook as the client and MAPI as the API. If you consider what Microsoft Exchange offers as the “full” set of features, no other replacement offers 100 percent of the features exactly as provided by Microsoft Exchange Server—even those considered drop-in replacements. The home page for the Microsoft Exchange server is www.microsoft.com/exchange/.

CommuniGate Pro

CommuniGate Pro is a proprietary, drop-in alternative to Microsoft Exchange Server, providing email, webmail, Lightweight Directory Access Protocol (LDAP) directories, a web server, file server, contacts, calendaring (third party), Voice over IP (VoIP), and a list server. The CommuniGate Pro MAPI Connector provides access to the server from Microsoft Outlook and other MAPI-enabled clients. The home page for this server is www.stalker.com/.

Oracle Beehive

Oracle Beehive is probably the closest that you will get to an Exchange replacement. It enables you to collaborate with instant messaging, email, file sharing (workspaces), calendaring, and other tools. Beehive is available for Linux platforms, and its home page is www.oracle.com/us/products/middleware/beehive/index.html.

Bynari

Bynari provides a proprietary group of servers to act as a drop-in replacement for Microsoft Exchange Server for email, calendaring, public folders, scheduling, address book, webmail, and contacts. Although it runs on Linux, it offers no Linux clients, although you can use it with Evolution and Thunderbird, and the connector provides services to Microsoft Outlook only. The home page is www.bynari.net/.

Open-Xchange

Open-Xchange has a great pedigree, having been owned and developed by Novell/SUSE until being spun off by itself into its own company. Working with open standards, it provides a number of collaboration options and is firmly based on Linux. It can work with a wide variety of protocols, making it one of the best connected suites available. You can get the open-source version at www.open-xchange.com.

Horde

Horde is a PHP-based application framework. When combined with an HTTP server (Apache, Microsoft IIS, Netscape) and MySQL database, IMP/Horde offers modules that provide webmail, contact manager, calendar, CVS viewer, file manager, time tracking, email filter rules manager, notes, tasks, chat, newsgroups, forms, bug tracking, FAQ repository, and presentations. The home page is www.horde.org/.

References

Image www.sendmail.org/—The Sendmail home page. Here you can find configuration information and FAQs regarding the Sendmail MTA.

Image www.postfix.org/—The Postfix home page. If you are using the Postfix MTA, you can find documentation and sample configurations at this site.

Image help.ubuntu.com/community/Postfix—Ubuntu community documentation for Postfix.

Image www.qmail.org/—The home page for the Qmail MTA. It contains documentation and links to other resources on Qmail.

Image https://help.ubuntu.com/community/ClamAV—Ubuntu community documentation for ClamAV.

Image www.rfc-editor.org/—A repository of Request For Comments (RFCs), which define the technical “rules” of modern computer usage.

Image www.procmail.org/—The Procmail home page.

Image Sendmail (O’Reilly Publishing) by Brian Costales, Claus Assmann, George Jansen, and Gregory Neil Shapiro, ISBN: 0-596-51029-2—The de facto standard guide for everything Sendmail. It is loaded with more than 1,000 pages, which gives you an idea of how complicated Sendmail really is.

Image Postfix (Sams Publishing) by Richard Blum, ISBN: 0-672-32114-9—An excellent book from Sams Publishing that covers the Postfix MTA.

Image Postfix: The Definitive Guide (O’Reilly Publishing) by Kyle D. Dent, ISBN: 0-596-00212-2—Another excellent resource for Postfix.

Image Running Qmail (Sams Publishing) by Richard Blum, ISBN: 0-672-31945-4—This is similar to the Postfix book from Sams Publishing except that it covers the Qmail MTA.