Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Debian GNU-Linux Bible.pdf
Скачиваний:
22
Добавлен:
21.02.2016
Размер:
7.08 Mб
Скачать

Mail

Of any application used on a computer system, e-mail ranks number. Even over the Internet, more traffic is

taken up by e-mail than by other sources. The point of e-mail is to communicate with others — sending letters, notes, and more. The muscle behind this mass transfer of communications are Mail Transfer Agents (MTAs). The mail system can be divided into two main parts: Mail Transfer Agents and Mail User Agents (MUAs). MUAs are clients that communicate with the MTAs.

This chapter covers the basics of setting up an e-mail server on your system. From there, you can take it farther by setting it up to process mailing lists, to process mail for virtual domains, and even to relay mail to another mail server. In addition to handling incoming mail sent to your server, clients need to retrieve their mail from your machine. For more information on the available clients that communicate with the servers you set up in this chapter, see Chapter 6.

Understanding Internet E-Mail

Protocols and Standards

In the early days of the Internet, many standards called Requests for Comments (RFCs) were created. Some of these standards are still used today. One such standard is the Mail Transfer Protocol, which developed in 1981 into the Simple Mail Transfer Protocol (SMTP). SMTP has been adopted primarily as the standard for transferring electronic mail over the Internet. Since its inception, SMTP has continued to develop to what it is today.

As SMTP continued to develop, other protocols emerged to work with mail servers servers, such as the Post Office Protocol (POP) and the Internet Mail Access Protocol (IMAP). These protocols developed as a means for clients to retrieve mail. Other protocols forced the development of sendmail,

25C H A P T E R

In This Chapter

Understanding Internet e-mail protocols and standards

Using SMTP mail servers

General tips and tools

Setting up POP and IMAP: client daemons

Getting help

518 Part V Linux Server

which was created by Eric Allman while at U. C. Berkeley. This program was a little different in that it could receive e-mail from various networks, fix the messages that would otherwise have been rejected, and pass the messages along to their final destination. To accomplish this feat, sendmail became extremely complex. Volumes have been written to explain how it works, with most barely scratching the surface.

The Post Office Protocol (POP) grew in popularity and has become the leading protocol for mail clients, primarily because this is the best way for users to dial into their ISP and download their mail. Having gone through several revisions, the most current being POP3, POP has flourished. Client software, which uses POP, can be found on nearly every platform. This protocol enables a client to connect to a remote mail server; log in using the user ID and password; and retrieve e-mail to a local machine for later viewing.

If a person needs to access e-mail from more than one location or machine, however, POP doesn’t work very well. This is one of the drawbacks of using POP. Another limitation is that POP can only access one folder on the remote mail machine. Some clients enable users to create folders to sort and manage their e-mail, but the folders can only reside on the local machine. For example, if you use a Windows e-mail client such as Eudora, Pegasus Mail, or Outlook Express, you can access your e-mail from a Linux mail server using the POP3 protocol, but it only picks up mail from one folder (the inbox) from the mail server. If you went to another computer and tried to access the e-mail there, you would not be able to because the mail is now on the first machine, where you used the Windows mail client.

This brings our discussion to the client mail protocol, which is gaining popularity as users need to use more than one computer to access their mail. The IMAP protocol, now in its fourth version, avoids POP’s limitations. More people are traveling with their laptops, while using desktops at home and at work. IMAP4 lets users connect to the mail server, create the folders on the server, access those folders, and get their mail from any machine with an IMAP client. IMAP clients exist for all the major platforms, and their numbers are growing.

IMAP also keeps track of the state of the mail — read, unread, and marked for deletion. This aspect of IMAP enables you to check your mail on one machine, read a few messages, shut down the first machine, and go to another machine to finish reading your mail. For those who travel, this can be a lifesaver. If you are in a hurry, you can read only those messages you deem critical. You can determine which are critical by checking the message headers, downloading only those messages you need immediately. Later, you can access the rest of the messages from any other computer.

For all this to work, the correct applications need to be loaded on the server. Table 25-1 lists some of the Debian-packaged applications for a mail server. The packages are sorted according to category: — SMTP, POP, IMAP, and Tools. The Tools category includes the programs that work with the mail servers, such as a mailing list server, or the tool that helps send mail through a firewall.

Chapter 25 Mail 519

Table 25-1

Mail servers and tools

Type

Name

Description

 

 

 

SMTP

 

 

 

sendmail

The most popular e-mail server, and also the most

 

 

versatile. However, configuration can be tricky.

 

exim

An easy-to-configure mail server

 

postfix

A high-performance mail server

POP

 

 

 

pop3d

A standard pop server for client access

 

qpopper

An enhanced mail pop server for client access

 

 

 

IMAP

 

 

 

imap

A standard imap server for client access

Tools

 

 

 

smtpd

A mail proxy for firewalls

 

berolist

An easy-to-use and install mailing list server

 

biff

A mail notification utility

 

 

 

Tip

With biff installed, you can add biff y to your .bashrc file to get notifications

 

when new mail arrives for you.

 

exim

The Debian choice of mail servers is exim. This is a replacement mail server for sendmail. It is the simplest, by far, to configure. Users must answer a series of questions at the time of install. Understanding these questions, and the terms used, will enable you to better configure a working server. The following sections will help get you started.

Because exim is simpler to configure than sendmail, it’s less flexible sendmail in some respects. For instance, exim requires that every address be associated with a domain name. If one is missing, it will add it to the address.

Inversely, exim can limit the relaying of messages to only certain domains. This avoids the relaying of bulk spam e-mail, which, in my opinion, has reached epidemic proportions. You can find comprehensive data about the exim package in the

/usr/doc/exim/spec.txt file.

520 Part V Linux Server

Questions during installation

When you install exim using dselect, you will proceed through a series of questions or steps during the configuration stage of the installation. Reviewing each of the questions and steps here will save you some time and trouble before you have to answer the questions on your computer.

The first step simply lets you know that you are about to start configuring the exim package. Press Enter to begin the configuration.

1.Here you are given five options that specify how this mail server is to be used. These options are as follows:

Internet Site — Mail is sent and received directly using SMTP.

Internet Site Using a Smart Host — This is primarily used for dial-up systems. You can receive mail directly or by using a utility such as fetchmail. Sent mail goes to a smart host (such as an ISP mail server).

Satellite System — All mail is sent to another machine (smart host) for delivery, and no mail is received locally. Use this option for workstations on a network.

Local Delivery Only — This machine is not on a network. Only mail for local users is delivered. This option is for a stand-alone system.

No Configuration — Nothing will be configured and the mail system cannot be used. The configuration must be completed manually or rerun with the /usr/sbin/eximconfig script as root.

In most cases, the first two options are used.

2.What is the visible name of your system? This will appear on outgoing messages. You can use the domain name (domain.com) of your system.

Press Enter to accept the default name or retype the name you want to use.

3.Does the system have any other names that need to appear on incoming messages? Use this for systems with multiple domain names.

Add each name separated by a space or comma. If no additional domain names are needed for this machine, enter none.

4.Name the domains that you are willing to relay. This means that you will accept mail for them, but they are not local domains. Enter any domain that specifies you as the MX (mail exchanger; their mail server).

Use spaces and commas to separate each domain. You can also use wildcards. Enter none if no domains apply.

5.If you want to relay networks for local machines, use the standard address/length format (192.168.123.213/24) for each network. You can also use IPv6 standard addresses.

Press Enter if there is no network to relay.

Chapter 25 Mail 521

6.Do you wish to filter spam using the Realtime Blackhole List? You can filter (f), reject (r), or not use (n) this option.

The default is not to use this option (n). If you choose to filter (f), you will be asked for the Internet address for the filter list. You can press Enter to accept the default address.

7.Who should the postmaster and root accounts be redirected to? This should be the administrator of the system.

Enter the name of the account that exists on this machine. The configuration will create an alias file or replace an existing one. The default is y, to replace the existing one.

8.Lastly, you can review the settings you’ve made during the configuration. Press Enter to accept them.

This completes the configuration of exim for your system. It can now send and receive e-mail.

The exim configuration file

From time to time, you may need to reconfigure your mail system in order to accomplish the mailing activities you want to perform. This may require modifying the configuration file. The information for the exim application is kept in the /etc/ exim.conf file, and is relatively easy to modify.

Most of the file can be read and understood by the variable names. A few parameters are a bit cryptic. I suggest leaving these alone until you have a clear understanding of them. The configuration file’s major components are covered in the following sections.

Main settings

The main settings control the overall system parameters. The bulk of the necessary configuring is done at the beginning of this file. This file was modified when exim was initially installed by the dselect configuration script. Among the settings made here are the qualified, local, and relayed domain names. These are domain names that have been listed as the MX record in the DNS. You can also set usernames for which no mail will be accepted, and the names of trusted users.

qualify_domain = hoth.rhino-tech.com

# qualify_recipient =

local_domains = localhost:hoth.rhino-tech.com

local_domains_include_host = true local_domains_include_host_literals = true

522 Part V Linux Server

#relay_domains = #relay_domains_include_local_mx = true never_users = root

host_lookup = *

# headers_check_syntax #rbl_domains = rbl.maps.vix.com #rbl_reject_recipients = false #rbl_warn_header = true

host_accept_relay = localhost

# percent_hack_domains=*

trusted_users = mail smtp_verify = true gecos_pattern = ^([^,:]*) gecos_name = $1

smtp_accept_queue_per_connection = 100 freeze_tell_mailmaster = true

received_header_text = “Received: \

${if def:sender_rcvhost {from ${sender_rcvhost}\n\t}\ {${if def:sender_ident {from ${sender_ident} }}\ ${if def:sender_helo_name

{(helo=${sender_helo_name})\n\t}}}}\ by ${primary_hostname} \

${if def:received_protocol {with ${received_protocol}}} \

(Exim ${version_number} #${compile_number} (Debian))\n\t\

id ${message_id}\

${if def:received_for {\n\tfor <$received_for>}}”

end

Transport configuration

This section sets the transport that is used for local delivery to user mailboxes. On Debian systems, group mail is set to write to the /var/spool/mail directory. This section also sets how pipes are used when in alias and .forward files. Autoreplies also are handled in this section.

local_delivery: driver = appendfile group = mail

mode = 0660 mode_fail_narrower = false envelope_to_add = true

file = /var/spool/mail/${local_part}

Chapter 25 Mail 523

address_pipe: driver = pipe return_output

address_file:

driver = appendfile

address_directory: driver = appendfile no_from_hack prefix = “”

suffix = “”

# maildir_format

address_reply: driver = autoreply

procmail_pipe: driver = pipe

command = “/usr/bin/procmail -d ${local_part}” return_path_add

delivery_date_add envelope_to_add check_string = “From “ escape_string = “>From “ user = $local_part group = mail

remote_smtp: driver = smtp

end

Directors configuration

This section controls local mail delivery, aliasing, and forwarding. The drivers, location, and transports are all set here. Local mail gets matched with the local user’s mailbox. The location of the alias file is set here, as is the file to which the user forwards his or her mail.

real_local: prefix = real-

driver = localuser transport = local_delivery

system_aliases: driver = aliasfile

file_transport = address_file pipe_transport = address_pipe file = /etc/aliases search_type = lsearch

# user = list

524 Part V Linux Server

procmail:

driver = localuser transport = procmail_pipe require_files =

${local_part}:+${home}:+${home}/.procmailrc:+/usr/bin/procmail no_verify

userforward:

driver = forwardfile file_transport = address_file pipe_transport = address_pipe reply_transport = address_reply no_verify

check_ancestor file = .forward modemask = 002 filter

localuser:

driver = localuser transport = local_delivery

end

Routers configuration

The setting in this section routes, through SMTP, mail addressed outside of the domains hosted by this server. The lookuphost option uses the default DNS to look up the domain, and the literal option uses the exact IP address.

lookuphost:

driver = lookuphost transport = remote_smtp

literal:

driver = ipliteral transport = remote_smtp

end

Retry configuration

This section sets the rules for retrying to send mail. The settings in the following example try to resend the message every 15 minutes for two hours. After two hours, retries are attempted every factor of 1.5, up to 16 hours. Then a try is made every eight hours for four days from the first failed attempt to deliver the message.

# Domain

Error

Retries

# ------

-----

-------

*

*

F,2h,15m; G,16h,2h,1.5; F,4d,8h

end

 

 

Chapter 25 Mail 525

Rewrite configuration

This section specifies where to look up the real mailing address for all local users, and rewrites it in the mail. This is useful for users without a domain of their own.

*@mail.mydomain.com ${lookup{$1}lsearch{/etc/emailaddresses}\

{$value}fail} bcfrF

Using Sendmail

Sendmail set the standard for Internet mail and it remains the most widely used e-mail package on Internet systems. Sendmail is used by Linux systems and the various UNIX systems alike. If flexibility is what you are looking for in a mail system, you’ve come to the right place.

Note Eric Allman, creator of sendmail, has gone on to create a company around the sendmail program. The core application of sendmail is still available as an open source program. The company makes its money by providing support to businesses, and offers enhanced versions of sendmail. These enhanced versions include a Web-based configuration utility for installing, configuring, and maintaining sendmail on the server. The company’s site is located at www.sendmail. com, whereas information about the free versions of sendmail can be found at www.sendmail.org.

In spite of its popularity, it is also one of the more complex packages to install, configure, and keep running. To give you an idea of its complexity, the main configuration file contains hundreds of lines of customizable code. Granted, under normal circumstances, no one would need to touch them. The Debian package of sendmail includes a configuration script to assist in making the configuration of sendmail a little less painful. (You can rerun the configuration script later using /usr/sbin/ sendmailconfig.)

Questions during installation

If you choose to install sendmail through the dselect installation program (which I recommend), you’ll be asked a series of questions to help you configure it for use with your particular environment. It is critical that sendmail be configured correctly in order for it to function properly. The following questions are numbered, although the configuration script questions are not. This helps you keep track of where you are in the process and how much further you have to go.

1.Introduction — Here you are introduced to the sendmail configuration. You must answer the following questions to complete the installation and configuration of sendmail. Most of the questions have a default answer, which will work for most installations.

Press Enter to continue.

526 Part V Linux Server

2.Mail Name — This is the host name that is shown on outgoing messages. For Internet mail, it must be a Fully Qualified Domain Name (FQDN). This would look something like domain.com.

To accept the default, press Enter or type in a new FQDN.

3.Smart Host — A smart host can deliver external mail to the Internet. With a smart host, you don’t need a DNS or a dedicated connection. This option works well for dial-up users or people who sit behind a firewall. Generally, the smart host will be the ISP’s mail server.

Enter the name of the smart host or leave it blank. Press Enter.

4.Address Canonification — Enabled by default, you are asked if want to disable this. This feature resolves addresses to their host names. Under normal circumstances, you want to leave this enabled.

Press Enter to accept the No default.

5.SMTP Mailer — This enables your computer to exchange mail with other mail servers. Communicating with other mail servers is very important when working on the Internet. If you work on an isolated network and have no need (nor ever will) to correspond with other networks, you could disable this feature.

This should be enabled in most cases. Press Enter to accept the default.

6.Masquerade Envelope — This enables mail coming from your machine (test.domain.com) to appear as if it came from the server (domain.com). This is helpful when working with a smart host.

Press Enter to accept this option.

7.All Masquerade — Enabled, this causes all mail being sent to have @domain.com added to the name. This may cause problems if you send mail to a mailing list called mail list, because maillist@domain.com does not exist. Leave this feature disabled unless you know what you are doing.

Press Enter to accept the default.

8.Always Add Domain — This adds the domain name to the sender’s name. Normally this doesn’t get added. The sender usually uses a complete name when creating a message.

Press Enter to accept the default.

9.Mail Acceptance — This tells sendmail to accept mail for your mail name (domain.com). You may want to disable this if mail for domain.com is directed in the DNS to another machine.

It is safe to leave this as Y(es).

10.Alternate Names — You can add acceptable mail names other than domain.com. This options works for multi-domain machines. You can add as many names as you need. Separate each name with a space. This option is saved in the sendmail.cw file.

Chapter 25 Mail 527

Type NONE to eliminate this option, or press Enter if you don’t have any to add but want to keep the option.

11.Trusted Users — This enables a special group of users, such as list servers. Use the names of those system users (not real people) with this feature. This option is saved in the sendmail.ct file. The people listed here are allowed to do certain things that would ordinarily raise flags of suspicion inside sendmail, such as masquerade as other users.

Separate each name with a space or type NONE to disable this option. Press Enter to keep the option without using it.

12.Redirect Feature — This enables the system to send an error message to the sender of an e-mail message sent to a user’s former e-mail address, and adds the user’s new email address. Add an entry to the /etc/mail/aliases file the name with <new-address>.REDIRECT as the aliased name. The sender will receive the error message with the new address.

Press Enter to keep this option disabled unless your system is likely to have a high turnover of users.

13.UUCP Addresses — Answering Yes to this enables sendmail to be smart about UUCP addresses. If you use a smart host, answer Yes to this to prevent a mail loop, unless the smart host does not deal with UUCP addresses.

Answer N(o) to this only if you are sure that no UUCP addresses are used on the mail system.

14.Sticky Host — Enabling this option sets domain.com as a distinct namespace. Mail sent to user@domain.com is marked as sticky and is not compared against local addresses.

Leave this option disabled if in doubt.

15.DNS — Enable this option if you have access to a Domain Name Server and are connected to the Internet. This option includes systems connected to and used as an ISP for mail services.

Press Enter to accept Y(es).

16.Best MX is Local — This option generates additional DNS traffic, which is OK for low to medium traffic hosts. Enabling this option causes sendmail to accept mail from any host that lists this machine as best possible MX record, as though the mail were addressed locally. This feature cannot be used if you have a wildcard MX record that matches your domain.

Press Enter to accept the default.

17.Mailertable — This enables the use of mail routing rules found in the

/etc/mail/mailertable file. Mailers like ifmail and fax programs should use this option. Otherwise, leave the option disabled.

The default disables this option.

528 Part V Linux Server

18.Sendmail Restricted Shell — This feature causes sendmail to use the restricted shell program (smarsh) instead of /bin/sh for mailing to programs. Enabling this restricts programs that can be run via e-mail to only those programs that appear in a special directory for heightened security.

The default is disabled.

19.Mailer Name — This is the name that is internally generated for outgoing messages. The default is MAILER-DAEMON, but it can be changed to something like POSTMASTER instead if desired.

Press Enter to accept the default name, or enter a new name.

20.Me Too — Enabling this option includes the sender in a group expansion of e-mail names. This enables a sender’s address to be included in a group mailing. It’s OK to leave this disabled.

Press Enter to keep this option disabled.

21.Message Timeouts — A warning message is sent to the sender if a message cannot be delivered in a reasonable amount of time. The default time is four hours for a warning message, and five days for a failure notice. Some people think that a four-hour warning is premature. If you agree, you can extend the time for the warning message. However, from the sender’s point of view, four hours may be a very long time.

Press Enter to accept the default times.

The script finishes at this point and completes the installation. You may find that a few errors occur as the script completes. One possible error is that some missing files were identified. This error is more a warning message than a critical error.

Possible missing files are /etc/mail/relay-domains and /etc/mail/users. These files can be added manually if they are needed. The warning resulted from only accepting the defaults during the configuration, leaving no information to be created in these files. The missing files will not prevent sendmail from working.

Many of the files that were modified will end up in the /etc/mail directory. You can make changes to these files by hand at any time after the installation. Note, though, that incorrect file contents may result in the sendmail server not working.

Alternatively configuring sendmail

You can configure sendmail manually through a text editor. This should be done only if you have some understanding of the configuration file. This file uses a somewhat cryptic code in its configuration. The main file is located in /etc/mail/ sendmail.cf and is divided into several sections. The purpose of some of the sections are obvious by their titles, while other sections seem more ambiguous, such as the section named Ruleset 96 -- bottom half of ruleset 3.

Chapter 25 Mail 529

Tip I recommend making a copy of the original configuration file before making any manual changes to it. You never know when something may go awry, causing havoc with the original setup. Having a backup of the working file gives you an out if you need to start at the beginning again.

To give you an idea of the substance of the file, here is a sample of its code:

################################################

### Ruleset 96 -- bottom half of ruleset 3 ###

################################################

S96

 

 

 

 

# handle special cases for local names

 

 

R$* < @ localhost > $*

$: $1 < @ $j . > $2

no domain at

all

 

 

 

 

R$* < @ localhost . $m > $* $: $1 < @ $j . > $2

local

domain

 

 

 

 

R$* < @ [ $+ ] > $*

 

$: $1 < @@ [ $2 ] > $3

mark

[a.b.c.d]

 

 

 

 

R$* < @@ $=w > $*

$: $1 < @ $j . > $3

self-literal

R$* < @@ $+ > $*

$@ $1 < @ $2 > $3

canon IP addr

#pass to name server to make hostname canonical R$* < @ $* $~P > $* $: $1 < @ $[ $2 $3 $] > $4

#local host aliases and pseudo-domains are always canonical

R$* < @ $=w > $*

$: $1 < @ $2 . > $3

R$* < @ $j > $*

$: $1 < @ $j . > $2

R$* < @ $=M > $*

$: $1 < @ $2 . > $3

R$* < @ $* $=P > $*

$: $1 < @ $2 $3 . > $4

R$* < @ $* . . > $*

$1 < @ $2 . > $3

You can see from this portion of the code that the sendmail configuration file takes some effort to understand. Each character in the line means something. Detailed coverage of each of these commands is beyond the scope of this book. However, the script that runs at the time of installation will take care of most situations.

Testing and using sendmail

You can test sendmail after you have it installed by sending mail through it. Create a text file using an editor such as vi. The contents of the text file can be something as simple as this is a test. Use thefollowing command line to send the file to yourself, assuming your username is jo:

& /usr/sbin/sendmail -v jo < letter

530 Part V Linux Server

The results of the test should appear as follows:

jo... Connecting to local...

jo... Sent

The -v tells sendmail that you want to use it in verbose mode, which means it prints everything it does. The account the mail was sent to is jo, and the letter is what you created. Now jo should have some mail if everything worked. Log in as jo to get the mail. You can also include all the To:, From:, and Subject: information usually found in messages.

Normally, sendmail is used through some type of client. Some situations may call for sending mail through the command line, in which case the previous command will work. Some examples of situations in which you might want to use sendmail from the command line include during, after, or as a result of an automated task. In this way, sendmail can notify administrators of problems or the completion of tasks, or it can broadcast an e-mail message.

General Mail Considerations

Now that you have a mail server installed on your system, you need to understand a few topics. that tend to affect more than one specific mail system. As such, they are covered in the following sections under different categories.

E-mail aliases

Most e-mail servers make use of an alias file. Because it is not recommended that certain accounts log in to a console such as root, daemon, and several others, mail sent to these accounts can be rerouted to another account that does log in on a regular basis. Mail sent to these system accounts, usually error messages, typically get aliased to the root account. Then the root account can be aliased to the administrator of the system. This just means that when the server goes to send mail to one of these accounts, it will be redirected to whomever needs to see the mail. The alias information is kept in /etc/aliases (or alternately /etc/mail/aliases, depending on your choice of mail server), which can be edited so that the correct people receive the mail notices.

You can also add virtual accounts in this file. A virtual account is not a real account, but a name by which users can receive e-mail. For instance, “webmaster” may not be an account set up for log in, but the person who manages the Web pages may want to use that ID for e-mail. In cases where several people may rotate through a position, it’s easier to change a name in a file to redirect mail, than to change an e-mail address on hundreds of Web pages.

Chapter 25 Mail 531

After all changes have been made to the aliases file, a database must be created for the mail server to read. This is done easily with the newaliases command. You must be in the directory of the aliases file, and then issue the command. If all the alias names and formats are correct, a database will be created; otherwise, you may receive error statements that necessitate correcting the file.

Forwarding your mail

Today, many people have more than one e-mail account through the Internet. To avoid confusion, all the mail from one system’s e-mail address can be redirected to an account on another system. This is known as forwarding. Forwarding e-mail is very useful.

You may work in an environment with several servers running. These servers can be set up to automatically generate a report, which can be e-mailed to the administrator of the mail server. The administrative account can then forward the mail to a central location, where the administrator can read the report. This enables the administrator to avoid logging on to each server to read the e-mail.

Similarly, an individual user can forward mail from one e-mail address to another, be it on the same machine or to another system. Suppose that an individual is expecting an important e-mail message, but is going to be away on vacation. With one of the many available free Internet e-mail accounts, which can be accessed anywhere, he or she can temporarily forward any messages.

Caution

As with most text-based Internet tools, e-mail is also subject to security risks.

 

Sending and receiving e-mail is not at all secure. There are some methods, how-

 

ever, that can help to increase the security of e-mail messages, such as encrypting

 

the message and using encryption keys. See Chapter 19 for more information on

 

security.

To forward your mail to another address, you must create a file in the home account location. Create the ~/.forward file and add a line with the e-mail address to which you would like the mail forwarded. For instance, if my e-mail address were jo@domain.com and I wanted to have my e-mail forwarded to jo@mydomain.com, I would do the following:

$ vi ~/.forward

In the file, I would add jo@mydomain.com, and then save and exit the editor. Now, whenever mail is sent to jo@domain.com, it will be forwarded to jo@mydomain.com instead. If you wish to cancel the forwarding, you can simply delete the ~/.forward file.

532 Part V Linux Server

Virtual mail server

Virtual mail server is not a function that most individuals would want to use; however, for businesses that host Web pages, process e-mail, and provide other Internet-related services, it is an important one.

The virtual mail server receives mail for a domain that doesn’t have a real machine. One method of working around this is to use the relay functions with the mail servers. This enables mail to be received on a mail server without the machine having the same domain name. The drawback to this method is that each address must have a unique name. Two domains with the same account ID will end up with mail going to the one account; for instance, jo@domain.com and jo@example.com will be treated as the same address.

Alternatively, virtual mail server can be set up to receive mail addressed to anything@mydomain.com, which is routed to only one account. For instance, suppose mail sent to sale@mydomain.com and mail sent to debianrules@mydomain. com is routed to the account jo on the mail.domain.com machine. This way, Jo can pick up her mail whenever she wants. In other words, she can have mail sent to any name as long as it ends in @mydomain.com.

In order to set up sendmail to route mail sent to anything for a domain, you must add a line to the /etc/mail/sendmail.cf file. Always make a back up copy of the configuration file before making any changes. Use an editor and locate section 98 (S98). If you are using vi as your editor, use the search command to find this section (/S98). After this section identifier, add a line that looks like the following:

R$* < $* domain.com. >

$#local $@ $:username

Replace domain.com with the name of the domain that will be virtually hosted. There must be a TAB between the two halves of the command. After R$* < $* domain.com. >, enter a TAB and then finish the line. Replace username with the account name to which the mail will be sent. If the TAB does not appear in the line, the virtual hosting will not work.

Once you have edited the configuration file, restart the sendmail service. Following are the commands to accomplish this:

#/etc/init.d/sendmail stop

#/etc/init.d/sendmail start

Sendmail will now be ready to receive mail from the new virtual domains. You can test mail sent to the new domains in the same way that you tested to see if sendmail worked initially. You should be able to send mail to any name as long as it is addressed to the virtually hosted domain.

Chapter 25 Mail 533

DNS and Internet mail

On the Internet or within a local network, where a Domain Name Server (DNS) is used to match domain names with actual IP addresses, mail is not handled in the same way. The DNS just wants to know the names of the mail exchangers; that is, the identities of the mail servers that can receive mail for a domain or forward it along. Each domain’s mail server, or mail exchanger, needs an MX (Mail Exchanger) record created for it. It also needs to be registered.

If there is more than one mail exchanger for a domain, each MX record is weighted for priority. Even on a domain that has only one mail exchanger, that mail exchanger is still weighted with a priority. The number representing the priority can be anything from 0 to 65,535 (that’s a lot of mail servers). Lower numbers are taken to be a higher priority.

For example, assume you have a network with a DNS. You have the mail services running on mail.domain.com, with the name of that machine registered in the DNS. You want all the mail for the domain domain.com to use mail.domain.com as the mail exchanger. You add an MX record to the DNS that would look like the following:

domain.com

IN

MX

1 mail.domain.com.

For larger facilities that require more than one mail server, add more servers, and then enter them in the DNS:

domain.com

IN

MX

10

mail1.domain.com.

domain.com

IN

MX

20

mail2.domain.com.

domain.com

IN

MX

20

mail3.domain.com.

Mail sent to domain.com using the preceding example would read the DNS as follows:

1.Mail would try to use the server with the lowest priority first — mail1.domain.com.

2.If mail.domain.com is unreachable, disconnected, or busy, then mail2.domain.com or mail3.domain.com would be tried next (both have the same priority).

3.The remaining two servers (mail2 and mail3) would be tried last.

This scheme of MX records enables the use of secondary and backup mail servers. Because the names are registered in the DNS, these servers need not exist on the same network or location on the Internet.

Cross-

To learn more about the Domain Name Server, see Chapter 5.

Reference

 

534 Part V Linux Server

Using mailing lists

Mailing list servers, commonly called list servers, automate the use of mailing lists, including distribution, subscriptions, and mailing requests — all without much human management. Computers can work much more efficiently than we can.

Think of the list server as a dedicated program that monitors a mailbox for new mail. It then determines if incoming mail has a command associated with it or if it should be sent back to the subscribers of the list. Typically, the commands appear in the form of subscribe or unsubscribe requests. This automatically enables users to add or remove their e-mail address from a list. Other commands might include requests for specific documentation.

Mailing lists are used everywhere as a common e-mail forum in which people to get help, share ideas, or, in some cases, just complain. And, yes, some mailing lists merely generate junk mail. Some e-mail claims to be from a mailing list when in fact it is just plain, old-fashioned spam (junk mail). The bottom of these messages gives a bogus e-mail address for you to unsubscribe, which only bounces back an error that no one exists at that address. Legitimate sites always respond to an unsubscribe request.

Debian uses many mailing lists. When you visit their Web site (www.debian.org/ MailingLists), you will see several mailing lists, all designed to enable people to communicate with one another on a variety of topics. There are lists for end users, developers, and specialty groups.

Setting Up POP

You were already introduced to the Post Office Protocol (POP) earlier in the chapter, but let’s review a few points. Because clients that use POP exist on nearly every platform, it has become the most popular protocol for picking up mail. The disadvantages of using POP are that you have to get all your mail at one time and can use only one computer to do so. This limits your flexibility and mobility because you can’t read your downloaded mail on another machine. Moreover, POP reads only one folder on the mail server. Clients compensate for this by creating local folders in which you can read, sort, and manage your mail.

Installing and configuring POP

To begin, you must install a POP server on the mail server. Table 25-1, at the beginning of the chapter, lists the two POP servers that Debian provides in package form: ipopd and qpopper. By default, Debian installs the ipopd package, which works fine; however, qpopper has some enhanced features added.

The packages are easy to install with dselect. The configuration stage of the install modifies the inetd.conf file so that the 110 TCP/IP port gets monitored for mail

Chapter 25 Mail 535

requests. This is the official port for POP services. The configuration script adds the following line to the /etc/inetd.conf file (in this case, I installed qpopper instead of ipopd):

pop-3

stream tcp

nowait root

/usr/sbin/tcpd

/usr/sbin/in.qpopper

If you make changes in the inetd.conf file, be sure to restart the inet service to activate the changes. Use the following command string to restart the service:

#/etc/init.d/inetd stop

#/etc/init.d/inetd start

Testing POP

With the POP service installed and running, you can now test the connection. Because POP uses a TCP/IP port, you can use telnet to connect to that port:

# telnet localhost pop-3

Alternately, you can check the port from a remote computer; use the same command, but replace localhost with the fully qualified domain name. You can also specify the port number (110) instead of using the name (pop-3). Here are the results of a connection to a server running qpopper as the POP server:

$ telnet localhost pop-3

Trying 127.0.0.1...

Connected to localhost. Escape character is ‘^]’.

+OK QPOP (version 2.53) at debian.mydomain.com starting. <3008.965876676@debi

an.rhino-tech.com> user jo

+OK Password required for jo. pass foobar14

+OK jo has 0 messages (0 octets). quit

+OK Pop server at debian.rhino-tech.com signing off. Connection closed by foreign host.

$

The bold text in the preceding example shows the commands that you would need to use. I logged in using user jo. The account for jo had to be created before testing the POP server. The server then responded by asking for a confirmation in the form of a password. I then entered the password command (pass) and the password. Note that the password is not encrypted for this test, so don’t use a critical account to do your testing (lest someone evil is watching in the background). Satisfied that the POP service was working properly, I issued the quit command to close the connection. The server then notified me that the connection was closed.

536 Part V Linux Server

Cross-

You can find out more about mail clients and retrieving mail in Chapter 6.

Reference

 

Setting Up IMAP

Although POP took off in the early days of computing, IMAP has found its niche as distributed computing has increased. IMAP users benefit from the capability to access more than one folder on the server, to mark mail as read or unread, and to leave mail on the server so that it is accessible from multiple machines.

Because an IMAP system leaves the mail on the server, the mail is available to you whether you are traveling with a laptop, working at the office with a desktop, or checking in at home with your personal system. This is the major advantage to using IMAP.

Installation and configuration

IMAP installation and configuration is as easy as they come. Using dselect to install the imap package, the configuration script that is executed at the end makes all the needed changes. IMAP also uses the inetd service to watch the TCP/IP port. Here is the line the script adds to the /etc/inetd.conf file:

imap2 stream

tcp

nowait

root

/usr/sbin/tcpd

/usr/sbin/imapd

 

You can make changes to this script, but I don’t advise it. The script automatically restarts the inet service; but if you need to restart the service for any reason, implement the following commands:

#/etc/init.d/inetd stop

#/etc/init.d/inetd start

With the software installed and running, the IMAP service is activated anytime a request comes into the IMAP port.

Testing IMAP

Once installed, you’ll want to test the service to make sure that it works. This can be done through a terminal connection to the machine, either locally or remotely. Initiate the connection to the IMAP port with the following command line:

telnet localhost imap2

This starts a connection to port 143 through TCP/IP, which is the IMAP port on your Debian machine. Alternatively, you can connect remotely by replacing localhost with the name or IP of the remote machine hosting the IMAP service.

Chapter 25 Mail 537

# telnet localhost imap2

Trying 127.0.0.1...

Connected to localhost. Escape character is ‘^]’.

* OK localhost IMAP4rev1 v12.264 server ready

A001 login jo foobar14

A001 OK LOGIN completed

A002 logout

* BYE debian.domain.com IMAP4rev1 server terminating connection A002 OK LOGOUT completed

Connection closed by foreign host.

In the previous example, you can see the response of the IMAP server. The bold text shows what I entered. The A001 login told the IMAP server that someone wanted to log in. It then took the next entry as the user ID, followed by the password. These must be valid accounts and passwords or the server will respond with a login request. Once the server validates the login, it will respond with a confirmation that the login is complete. You can then log out of the IMAP server.

Caution

Always keep the versions of all your servers up-to-date. Security holes are fixed

 

quickly, but it won’t matter if you keep running the old buggy versions of software.

 

See Chapter 19 for more details about security.

Getting Help

When you install mail serviceson your system, in most cases it should work. Of course, with no two machines alike, the potential for problems always exists.

The following guidelines will help you troubleshoot any problems with mail:

Make sure that you have an MX record in the DNS for each domain receiving mail. This entry should point to the machine that runs the mail server.

Make sure that the /etc/mail/sendmail.cw file is properly configured if you are using sendmail. It contains all domains for which this server is responsible for receiving mail.

The alias file (/etc/aliases or /etc/mail/aliases) should contain an entry for the postmaster, the mailer-daemon, or whatever name was set to receive error messages from the mail server. This name should be aliased to an administrator for the system. This will help to track down other problems.

A good source for help is always other users, peers, and administrators. You can find great advice and helpful hints through Web sites, newsgroups, and mailing lists. If you visit www.debian.org/MailLists, you’ll find tons of mailing lists of knowledgeable people to help answer your questions.

You might also find useful information at one of the Web sites focused on the various applications. Here are a few sites that might provide answers to your questions:

538 Part V Linux Server

www.exim.org — Site for the exim mail server

www.sendmail.org — Site for the Open Source version of Sendmail

www.imap.org — Site for the IMAP mail client server

No matter what the problem, it’s likely that someone else has battled with it. Be sure to thoroughly explain your problem when posting to a mailing list or newsgroup, or enlisting online support through a Web site.

Summary

This chapter has been fairly comprehensive in covering topics regarding electronic mail. You have learned about several mail-related programs, some used for transferring mail, and some used for retrieving mail. You’ve also learned about several mailrelated concepts:

MTA — A Mail Transfer Agent is a program that routes mail from system to system. These are the programs that actually deliver the mail to its destination.

SMTP — Simple Mail Transfer Protocol is the language the MTA programs use to communicate in order to transfer the mail. These programs don’t have to be the same program; they just need to be able to speak SMTP.

MUA — A Mail User Agent is a program that retrieves the mail. These are client applications, and are covered in Chapter 6.

POP — Post Office Protocol is the protocol that the MUA applications use to retrieve the mail. This protocol enables users to get their mail and remove it from the server. POP limits users to one machine from which to read their mail.

IMAP — Internet Mail Access Protocol enables users to access their mail on the server. Users can also leave their mail on the server, thus enabling them to access their mail from different machines and locations. This protocol also can mark the mail as read, unread, or deleted. It also can access more than one folder on the server, enabling users to manage their mail.

Also covered in this chapter was the installation and configuration of two mail servers. The Debian packages include configuration scripts to help configure these packages for most situations. You also learned about some common e-mail topics, including forwarding mail, setting up aliases, and virtual hosting e-mail. These topics can help you with most SMTP programs that you choose to install. You also learned how to install two protocols that are used to retrieve mail from the server: POP and IMAP. In addition, you were also introduced to mailing list servers.

You should now have the basic knowledge needed to set up and run your own mail server. Happy mailing.

What’s On the

CD-ROM

Appendix A provides you with information on the contents of the CD-ROM that accompanies this book.

There are 1,194 programs and supporting packages included on this CD. Among them are:

Gnome Desktop Environment

GIMP graphic design tool

Apache Web Server

Although Debian GNU/Linux offers its distribution for many platforms, the media that accompanies this book is only for the i386-based PC platform.

Using the CD with Linux

To install Debian GNU/Linux from the CD to your hard drive, follow the steps listed in Chapter 2 of this book. These instructions will thoroughly take you through the installation process.

What’s On the CD

The contents of this CD contain the core files for installing Debian GNU/Linux on your system. All software on this CD is free to use and free to copy under the GNU General Public License. The following summary shows some of the contents of the CD-ROM arranged by category.

A AP P E N D I X

540 Debian GNU/Linux Bible

Applications

The following applications are on the CD-ROM:

Graphical interfaces

A graphical interface provides a “point and click” environment where you can operate programs.

Gnome — A graphical desktop environment offering many customizable features.

For more information: www.gnome.org

WindowMaker — A window manager used to control the window environments for other programs to run in.

For more information: www.windowmaker.org

Development environments

Linux makes a stable environment for developing applications.

Perl — A popular scripting language used on several platforms.

Tc/Tkl — An interpretive language used mainly for graphical interfaces.

g++ — The equivalent to c++ for Linux using the C language.

Server Applications

Linux offers the stability, security, and control to become the platform for running various server functions.

Apache — The most popular Web server offering addition modules for specific customization.

For more information: www.apache.org

Samba — Allows Windows machines on a network to share files and resources from the Debian server.

For more information: www.samba.org

In addition to these programs, you will find a complement of other server applications like FTP, News, and Domain Name Services.

Source code

All source code for the programs are available through a mail in coupon found in the back of this book. Fill out the information on the coupon and mail it in. A CD with the source code will then get mail to you.

Appendix A What’s On the CD-ROM 541

Troubleshooting

If you have difficulty installing or using the CD-ROM programs, try the following solutions:

Enable CD booting from the system BIOS — Some systems set the boot device order. Make sure that the CD-ROM device is chosen before the hard drive C. If you have an older system, this may not be an option in which case you will need to follow the instructions in Chapter 2 on creating a boot disk. (Consult your systems manual on accessing the BIOS)

Make sure the Rescue disk is in the floppy drive — When booting the system using the floppies, the first floppy to use for booting is the rescue disk. You will then get asked for the root floppy once the system gets initialized.

If you still have trouble with the CD, please call the Hungry Minds Customer Service phone number: (800) 762-2974. Outside the United States, call (317) 572-3993. Hungry Minds will provide technical support only for installation and other general quality control items; for technical support on the applications themselves, consult the program’s vendor or author.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]