RedHat iTOps Tube

Tuesday, November 22, 2011

How Sendmail Works - 2

Outgoing Mail

The process is different when sending mail via the mail server. PC and Linux workstation users configure their e-mail software to make the mail server their outbound SMTP mail server.

If the mail is destined for a local user in the domain, then sendmail places the message in that person's mailbox so that they can retrieve it using one of the methods above.

If the mail is being sent to another domain, sendmail first uses DNS to get the MX record for the other domain. It then attempts to relay the mail to the appropriate destination mail server using the Simple Mail Transport Protocol (SMTP). One of the main advantages of mail relaying is that when a PC user A sends mail to user B on the Internet, the PC of user A can delegate the SMTP processing to the mail server.

Note: If mail relaying is not configured properly, then your mail server could be commandeered to relay spam. Simple sendmail security will be covered later.

Sendmail Macros

When mail passes through a sendmail server the mail routing information in its header is analyzed, and sometimes modified, according to the desires of the systems administrator. Using a series of highly complicated regular expressions listed in the /etc/mail/ file, sendmail inspects this header and then acts accordingly.

In recognition of the complexity of the /etc/mail/ file, a much simpler file named /etc/ was created, and it contains more understandable instructions for systems administrators to use. These are then interpreted by a number of macro routines to create the file. After editing, you must always run the macros and restart sendmail for the changes to take effect.

Each directive starts with a keyword, such as DOMAIN, FEATURE, or OSTYPE, followed by a subdirective and in some cases arguments. A typical example is.

As stated before, sendmail can handle both incoming and outgoing mail for your domain. Take a closer look.

FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl

The keywords usually define a subdirectory of /usr/share/sendmail-cf in which the macro may be found and the subdirective is usually the name of the macro file itself. So in the example, the macro name is /usr/share/sendmail-cf/feature/virtusertable.m4, and the instruction `\ hash -o /etc/mail/virtusertable.db' is being passed to it.

Notice that sendmail is sensitive to the quotation marks used in the m4 macro directives. They open with a grave mark and end with a single quote.


Some keywords, such as define for the definition of certain sendmail variables and MASQUERADE_DOMAIN, have no corresponding directories with matching macro files. The macros in the /usr/share/sendmail-cf/m4 directory deal with these.

Once you finish editing the file, you can then execute the make command while in the /etc/mail directory to regenerate the new file.

[root@bigboy tmp]# cd /etc/mail
[root@bigboy mail]# make

If there have been no changes to the files in /etc/mail since the last time make was run, then you'll get an error like this:

[root@bigboy mail]# make
make: Nothing to be done for `all'.
[root@bigboy mail]#

The make command actually generates the file using the m4 command. The m4 usage is simple, you just specify the name of the macro file as the argument, in this case, and redirect the output, which would normally go to the screen, to the file with the ">" redirector symbol.

 [root@bigboy tmp]# m4 /etc/mail/ > /etc/mail/

I'll discuss many of the features of the file later in the chapter.