Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

relayhost = mail.AbsoluteBSD.com

...............................................................................................

Email Aliases

The /etc/mail/aliases file contains redirections for mail sent to specific accounts. Although the aliases file originated with sendmail, many different mail programs understand it. Each line starts with an alias name, followed by a colon and a list of real users to forward the mail to.

Forwarding Email from One Account to Another

Many people prefer to have mail that is sent to "root" actually redirected to their email account. The following example forwards all email sent to root to another user:

...............................................................................................

root: mwlucas@absolutebsd.com

...............................................................................................

Forwarding Email from Nonexistent Accounts

Many email addresses don't have accounts associated with them. For example, Internet standards require any system that sends email to have a "postmaster" email address. Nobody wants to set up a separate account just for this. Instead, you can forward email from these addresses to a real account:

...............................................................................................

postmaster: root

...............................................................................................

The aliases file already contains a wide variety of standard aliases for addresses that are generally expected to be available at a server. Scan this file and update it for your systems.

Aliased Mailing Lists

You can also list multiple users to create small local mailing lists. This doesn't scale well when you have many users, but it's great for quick and simple problems.

...............................................................................................

sales: mwlucas, bpollock, sales@nostarch.com

...............................................................................................

Forwarding Email to Files

Among the alias file's more interesting features is the ability to redirect mail to something other than a mail account. If you list a filename, it appends the message to that file. You could maintain a permanent log of a user's mail with something like this:

323

...............................................................................................

username: /var/log/username−log, username

...............................................................................................

Forwarding Email to Programs

You can also send email to a program for automated handling. List the program name, preceded by the pipe (|) symbol. If you've written a script that processes incoming mail, for example, you can use this line to redirect the mail:

...............................................................................................

orders: |/usr/local/bin/process−orders.pl

...............................................................................................

Lists in Alias Files

Finally, you can include other files in the aliases file. This allows a user to modify an alias on her own.

...............................................................................................

clientlist: include:/usr/home/salesdude/clientaddresslist

...............................................................................................

In this example, the /usr/home/salesdude/clientaddresslist file is just a list of email addresses, one per line. This will allow your salesperson to maintain a list of clients, without bothering you each time a new contact needs to be added.

Activating Alias Changes

The only caveat with this simple system is that /etc/mail/aliases is not actually processed each time a message is received. Rather, the aliases file is used to build a small database file (/etc/mail/aliases.db) that postfix uses to route mail. Accessing a binary database is much faster than scanning a text configuration file, which becomes important on systems with scant processor power, or ones that handle high volumes of mail.

Any time you edit the aliases file, or any file that the alias file includes, you need to run newaliases to rebuild this database. You can safely run newaliases through cron; users maintaining include files won't see their changes until the cron job runs, but most users accept this if they know what to expect.

Email Logging

Almost all mail programs place log messages in /var/log/maillog. If you want to know what your server is doing, check that file. Remember, you can use tail −f /var/log/maillog to watch what's happening on your server as it occurs. The type of messages that show up in your log file vary with the mail server program you're using.

324

Virtual Domains

One of the main reasons FreeBSD is so popular is because it can support many, many domains on one server. Most people who want Internet service for a domain name have very simple needs: a Web page and email addresses. One FreeBSD machine can handle hundreds and hundreds of simple Web and email sites through the magic of virtual domains.

The idea behind a virtual domain is simple: It's an additional name for a server. The server is configured to handle Web requests or email for that domain. We'll visit the Web part when we discuss the Apache Web server in Chapter 15. For now, let's look at email.

To use the virtual domain feature, add the following line to main.cf:

...............................................................................................

virtual_maps = /usr/local/etc/postfix/virtual

...............................................................................................

This tells postfix where to look for virtual−domain information. Virtual−domain information is kept in a "map" that matches virtual users to real system users. By default, email is delivered to the user whose username matches the email name. For example, the mwlucas account on http://absolutebsd.com/ has the email address http://mwlucas@absolutebsd.com/. If I wanted to give the address http://mwlucas@vanhornefabrication.com/ to a customer, and put mail handling for that domain on the same server, by default his email would be deposited in my account. This is bad. The virtual domain email map tells postfix to drop email for that address into a different account.

Virtual Domain Maps

The format for the virtual file is very simple:

...............................................................................................

domainname.com

postmaster@domainname.com system−user1 user2@domainname.com system−user2 user4@domainname.com system−user3

...............................................................................................

First, you need the name of the domain you want to provide service to. Then you list valid email addresses and the user accounts or email addresses they are redirected to. For example, to provide a virtual domain for http://absolutebsd.com/ we might have a virtual file like this:

...............................................................................................

AbsoluteBSD.com

postmaster@AbsoluteBSD.com mwlucas sales@AbsoluteBSD.com sales@nostarch.com questions@AbsoluteBSD.com mwlucas refunds@AbsoluteBSD.com /dev/null

...............................................................................................

Messages for http://postmaster@absolutebsd.com/ are redirected to the mwlucas account. The http://sales@absolutebsd.com/ account is directed to an entirely different domain. The http://questions@absolutebsd.com/ address is also directed to mwlucas, while http://refunds@absolutebsd.com/ is copied to the system file /dev/null.

325

Like many other UNIX configuration files, the virtual domains table is actually kept in a small database file. When you edit the file, you need to update this database with postmap(8).

...............................................................................................

# postmap /usr/local/etc/postfix/virtual

...............................................................................................

Changes will take a moment or two to become visible, unless you forcibly reload the postfix configuration files. And that takes us nicely to our next topic.

Postfix Commands

Postfix includes several commands to simplify managing your email server. We'll look at the basics here.

postconf This program lists your entire postfix configuration setup, including the values of all variables.

postfix check This command examines your postfix configuration, and points out any particularly bad problems.

postfix start This command starts the postfix system.

postfix stop This (wait for it…) shuts down postfix.

postfix reload This command forces postfix to reexamine all its configuration files for changes. Postfix checks for changes every few minutes anyway; this is useful if you're in a hurry.

Finding the Correct Mail Host

So, we know how to transmit and receive email from server to server and from client to server. How does the email server know which remote server to send a piece of mail to?

When a mail server has a piece of email for a remote domain, it does a DNS check. The DNS record for a domain lists the mail servers for that domain as "MX" records (see Chapter 12). The mail server tries to deliver the mail to the email server with the lowest preference number first. If the preferred email server cannot be reached, the server tries the server with the second−lowest preference number. It tries successively less preferred servers until it either delivers the mail or it cannot deliver it anywhere.

Undeliverable Mail

If a message is undeliverable, the server places it in a queue. Every so often, it tries to transmit the message again. If the message cannot be delivered in five days, the message is returned to the sender as "undeliverable."

326