Network Administration: Configuring Sendmail
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:
The following sections describe the common configuration changes that you may need to make to sendmail.mc.
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:
Add dnl # to the beginning of this line to make it a comment.
Masquerading allows all the mail being sent from your domain to appear as if it came from the domain (for example, email@example.com) rather than from the individual hosts (like firstname.lastname@example.org). 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 email@example.com and have all mail sent to that account delivered to a user named willie. 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:
firstname.lastname@example.org willie email@example.com robert firstname.lastname@example.org robert
After you make your changes, you should restart the Sendmail service.