Configuring Sendmail


Although Fedora Core and FreeBSD already have Sendmail installed and configured for local delivery, you'll want to tweak the default configuration a bit to prevent abuse and to tell Sendmail what to do with mail destined for external systems.

Cygwin users don't have a Sendmail port to deal with, and Mac OS X users can skip ahead to the Postfix sections because Postfix is installed as part of their base operating system.

To configure Sendmail

Sendmail configuration has a reputation for being painful and error-prone. You might want to pick up a cup of your favorite beverage before diving in.

1.

Log in as root or use su to become root.

2.

cd /etc/mail

Sendmail's configuration files are collected in one standard location.

3.

Use your favorite text editor to edit the sendmail.mc file.

If you're using FreeBSD, you'll edit hostname.mc instead; the Sendmail configuration file on FreeBSD is named after the host.

4.

Because Sendmail's main configuration file gets processed with the M4 macro processor, follow these rules when editing:

  • Create comments, or end lines with the dnl command. This deletes the rest of the line (from dnl onward) from the output file.

  • Quote strings with a backtick and single quote. For example, the SMART_HOST macro must appear as `SMART_HOST' in the configuration file.

Sendmail or Postfix?

Choosing whether to use Sendmail or Postfix can be fairly straightforward. Your standard FreeBSD and Fedora Core installations include a configured Sendmail suitable for delivering messages locally. Similarly, Mac OS X comes with Postfix installed and ready. If you're content with the status quo, your work here is (almost) done. If you want to maximize the security of your system and minimize your administrative headaches, you should consider upgrading from Sendmail to Postfix.

If you're thinking of running Sendmail or Postfix on a Cygwin system, you might want to reconsider. Mixing Windows users, groups, and permissions with very Unix-specific applications that make lots of assumptions about their operating environment is going to be more work than setting up a small Fedora Core or FreeBSD system.

Of course, you should take a look at the documentation for both and pick the one that makes the most sense to you.


5.

If your system can't send mail directly to other hosts on the Internet (it should be able to, unless you're part of a residential ISP network, don't have a valid reverse DNS record, or have other configuration problems) and/or you want to use your ISP's system to send your mail, uncomment (remove the dnl command at the beginning of the line) the define(`SMART_HOST',...) line and change hostname to the fully qualified domain name of your ISP's SMTP relay: define(`SMART_HOST',`hostname')dnl

6.

If Sendmail should reject connections from other systems, find the DAEMON_OPTIONS macros and add this after the existing DAEMON_OPTIONS macros:

 DAEMON_OPTIONS(`Port=smtp  ,Addr=127.0.0.1, Name=MTA')dnl 

To allow connections from any system on your local network, comment out this line (Fedora Core includes this setting by default). Allowing connections from the LAN lets other systems use this machine as a relay.

Warning: To prevent connections from external systems, remember to block the SMTP port (25) at the firewall between your LAN and the Internet.

7.

To prevent access from systems with unresolvable domains (this is a spam risk!), comment out the accept_unresolvable_domains FEATURE macro, if one exists:

 dnl FEATURE  (`accept_unresolvable_domains') 

8.

If your system doesn't have a proper domain associated with it (for example, a small LAN in your basement probably doesn't have its own domain), uncomment or add (after the DAEMON_OPTIONS macros) the MASQUERADE_AS macro:

 MASQUERADE_AS(`yourisp')dnl 

Replace yourisp with the domain name of your ISP; all email coming from this system will appear to have been sent from yourisp instead of whatever internal domain name you've been using on the LAN.

9.

Save the Sendmail configuration file, and exit your editor.

10.

make

In the /etc/mail directory, running the make command (Code Listing 8.1) will rebuild the Sendmail databases and other files.

11.

make restart

Restart the Sendmail daemon so that it picks up the configuration changes.

Tip

  • Fedora Core users will need to install the sendmail-cf package before rebuilding Sendmail's configuration files. Use up2date to do this:

     up2date -i sendmail-cf 


Code listing 8.1. Using the make command to rebuild sendmail.cf from the sendmail.mc file.
 bsd# cd /etc/mail bsd# vi bsd.chrish.local.mc ... bsd# make /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4  bsd .chrish.local.mc > bsd.chrish.local.cf bsd# make restart Restarting: sendmail sendmail-clientmqueue. bsd# 

To configure aliases

Mail aliases let you create a virtual email address that distributes its mail to another alias, a local user, a local file, a command, or another address.

1.

Log in as root or use su to become root.

2.

cd /etc

The "aliases" file resides in the general configuration directory (although on FreeBSD it's actually in /etc/mail, and there's a symbolic link in /etc).

3.

Use your favorite text editor to edit the aliases file.

4.

Each line of the aliases file follows this form:

 name: addr_1, addr_2, ..., addr_n 

Where name is the alias; messages sent to this virtual email address will be distributed to the address (or addresses) listed on the rest of the line (addr_1,addr_2 , and so on). Only one address is required.

For example, maybe I want mail that is sent to root on this system to actually be delivered to the user chrish. Adding the following line to the aliases file accomplishes this:

 root: chrish 

Lines starting with a # character are comments.

5.

To send the email to a command, use |command as the address. You might use this to scan incoming email for viruses or dangerous attachments.

6.

You can send the email to a file by specifying a full path (/path/to/the/file) as the address.

7.

Email can be forwarded to a user on another system by using the user's email address (spamvictim@hotmail.com) as the address.

8.

Save the aliases file, then exit your editor.

9.

newaliases

Run the newaliases command (Code Listing 8.2) to update the aliases database and restart Sendmail.

Code listing 8.2. Rebuilding the email-address-alias database with the newaliases command.
 [root@dhcppc1 ~]# cd /etc [root@dhcppc1 etc]# vi aliases ... [root@dhcppc1 etc]# newaliases /etc/aliases: 80 aliases, longest 16 bytes, 845 bytes total [root@dhcppc1 etc]# 



    Unix Advanced. Visual QuickPro Guide
    Unix Advanced: Visual QuickPro Guide
    ISBN: 0321205499
    EAN: 2147483647
    Year: 2003
    Pages: 116

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net