Networking / Beginners

Modifying sendmail.mc

Sendmail is probably one of the most difficult programs to configure that you'll ever encounter. In fact, the basic configuration file, sendmail.cf, is well over a thousand lines long. You don't want to mess with this file if you can possibly avoid it.

Fortunately, you don't have to. The sendmail.cf configuration file is generated automatically from a much shorter file called sendmail.mc. This file contains special macros that are processed by a program called m4. The m4 program reads the macros in the sendmail.mc file and expands them to create the actual sendmail.cf file.

Even so, the sendmail.mc file is a few hundred lines long. Configuring Sendmail isn't for the faint of heart.

You can find the sendmail.mc and sendmail.cf files in the /etc/mail directory. Before you edit these files, you should make backup copies of the current files. That way, if you mess up your mail configuration, you can quickly return to a working configuration by reinstating your backup copies.

After you've made backup copies, you can safely edit sendmail.mc. When you're finished, you can regenerate the sendmail.cf file by entering these commands:

cd /etc/mail
m4 sendmail.mc > sendmail.cf
service sendmail restart

The first command changes the current working directory to /etc/mail. Then, the second command compiles the sendmail.mc command into the sendmail.cf command. Finally, the third command restarts the Sendmail service so that the changes will take effect.

You need to be aware of two strange conventions used in the sendmail.mc file:

  • Unlike most configuration files, comments don't begin with a hash mark (#). Instead, they begin with the letters dnl.
  • Strings are quoted in an unusual way. Instead of regular quotation marks or apostrophes, strings must begin with a backquote (`), which is located to the left of the numeral 1 on the keyboard and ends with an apostrophe ('), located to the right of the semicolon. So a properly quoted string looks like this:
MASQUERADE_AS(`mydomain.com')

The following sections describe the common configuration changes that you may need to make to sendmail.mc.

Enabling connections

The default configuration allows connections only from localhost. If you want Sendmail to work as a server for other computers on your network, look for the following line in the sendmail.mc file:

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

Add dnl # to the beginning of this line to make it a comment.

An open relay is a mail server that's configured to allow anyone to use it as a relay for sending mail. In short, an open relay sends mail when neither the sender nor the recipient is a local user. Spammers love open relays because they can use them to obscure the true origin of their junk e-mail. As a result, open relays are a major contributor to the Internet spam problem.

Fortunately, the default configuration for the current version of Sendmail (8.14) is to not allow open relaying. As a result, you have to go out of your way to become an open relay with Sendmail. In fact, you'll have to look up the lines you'd need to add to sendmail.mc to enable open relaying.

If you do need to allow relaying for specific hosts, create a file named relay-domains in /etc/mail. Then, add a line for each domain you want to allow relaying for. This line should contain nothing but the domain name. Then restart Sendmail.

Enabling masquerading

Masquerading allows all the mail being sent from your domain to appear as if it came from the domain (for example, wally@cleaver.net) rather than from the individual hosts (like wally@wally.cleaver.net). To enable masquerading, add lines similar to these:

MASQUERADE_AS(`cleaver.net')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(`cleaver.net')dnl

Setting up aliases

An alias - also known as a virtual user - is an incoming e-mail address that is automatically routed to local users. For example, you may want to create a generic account such as sales@mydomain.com and have all mail sent to that account delivered to a user named ryan. To do that, you edit the file / etc/mail/virtusers. This file starts out empty. To create a virtual user, just list the incoming e-mail address followed by the actual recipient.

For example, here's a virtusers file that defines several aliases:

sales@mydomain.com 	ryan
bob@mydomain.com 	harris
marketing@mydomain.com 	harris

After you make your changes, you should restart the Sendmail service.

[Previous] [Contents] [Next]