Learning the sendmail Configuration File

You don't need to understand everything in the sendmail configuration file, /etc/ mail/sendmail.cf, but you should know how that file is created. That way, you can make minor changes if necessary and regenerate the /etc/mail/sendmail.cf file.

To be able to regenerate the sendmail.cf file, you have to install the sendmail-cf package. To check whether the sendmail-cf package is installed, type rpm -q sendmail-cf. If the command does not print the name of the sendmail-cf package, you have to install the package. This RPM file is in the DVD-ROMs bundled with this book. To install that package, log in as root and mount the DVD-ROM with the following command:

mount /media/cdrom

Then change to the /media/cdrom/Fedora/RPMS directory and install the package by using the following code:

cd /media/cdrom/Fedora/RPMS rpm -ivh sendmail-cf*

The sendmail-cf package installs in the /usr/share/sendmail-cf directory all the files needed to generate a new sendmail.cf configuration file. As you learn in the next few sections, the sendmail.cf file is generated from a number of m4 macro files. These macro files are organized into a number of subdirectories under / usr/share/ sendmail-cf. You can read the README file in /usr/share/sendmail-cf to learn more about the creation of sendmail configuration files.

Now that you have taken care of the prerequisites, you can learn how to regenerate the sendmail.cf file.

Using the m4 Macro Processor

The m4 macro processor is used to generate the sendmail.cf configuration file, which comes with the sendmail package in Linux. The main macro file, sendmail.mc, is included with the sendmail package, but that file needs other m4 macro files that are in the sendmail-cf package. To be able to process the sendmail.mc file, you have to install the sendmail-cf package, as explained in the previous section. This section introduces you to the m4 macro processor.

A macro is a symbolic name for some action or a long string of characters. A macro processor such as m4 usually reads its input file and copies it to the output, processing the macros along the way. The processing of a macro generally involves performing some action and generating some output. Because a macro generates a lot more text in the output than merely the macro's name, the processing of macros is referred to as macro expansion.

cross ref

The m4 macro processor is the GNU implementation of the standard UNIX macro processor. Only a few simple m4 macros are described in this section, but there is much more to m4 than the simple examples shown here. It's essentially a new scripting language for generating configuration files. You can read the online manual about m4 by typing the command info m4 at a shell prompt. Chapter 23 describes how to read online help by using info.

Note that m4 is stream based (like the sed editor, described in Chapter 8). That means it copies the input characters to the output, while expanding any macros. The m4 macro processor does not have any concept of lines, so it copies newline characters to the output. That's why you see the word dnl in most m4 macro files; dnl is an m4 macro that stands for delete through newline. The dnl macro deletes all characters starting at the dnl up to and including the next newline character. The newline characters in the output don't cause any harm; they merely create unnecessary blank lines. The sendmail macro package uses dnl to avoid such blank lines in the output configuration file. Because dnl basically means delete everything up to the end of the line, m4 macro files also use dnl as the prefix for comment lines.

To see a very simple use of m4, consider the following m4 macro file that defines two macros — hello and bye — and uses them in a form letter:

dnl ################################################### dnl # File: ex.m4

dnl # A simple example of m4 macros dnl ###################################################

define("hello', "Dear Sir/Madam')dnl define("bye',

"Sincerely,

Customer Service')dnl dnl Now type the letter and use the macros hello,

This is to inform you that we received your recent inquiry. We will respond to your question soon.

Type this text using your favorite text editor, and save it in a file named ex.m4. You can name a macro file anything you like, but it is customary to use the .m4 extension for m4 macro files.

Before you process the macro file by using m4, note the following key points the preceding example illustrates:

♦ Use the dnl macro to start all the comment lines (for example, the first four lines in the example).

♦ End each macro definition with the dnl macro. Otherwise, when m4 processes the macro file, it produces a blank line for each macro definition.

♦ Use the built-in m4 command define to define a new macro. The macro name and the value are both enclosed between a pair of left and right quotes (*...'). Note that you cannot use the plain single quote to enclose the macro name and definition.

Now process the macro file ex.m4 by using m4 as follows:

Was this article helpful?

0 0
Make Money Writing

Make Money Writing

This Report Will Show You How To Make Money By Providing Writing Services To Other Internet Marketers. Learn how to make money by writing the right way. Grab your copy of this report now and learn. Why writing is a great way to earn money. How to compete with cheap writers, even if you charge a lot more money.

Get My Free Ebook


Post a comment