The components of sendmail.cf are
- /etc/mail/sendmail.mc
- /usr/share/sendmail-cf/m4/cf.m4
- /usr/share/sendmail-cf/m4/cfhead.m4
- /usr/share/sendmail-cf/sh/makeinfo.sh
- /usr/share/sendmail-cf/ostype/$1.m4
- /usr/share/sendmail-cf/mailer/$1.m4
- /usr/share/sendmail-cf/domain/$1.m4
- /usr/share/sendmail-cf/feature/$1.m4
- /usr/share/sendmail-cf/hack/$1.m4
- /usr/share/sendmail-cf/siteconfig/$1.m4
- /usr/share/sendmail-cf/m4/proto.m4
$1 will be replaced by the m4 processor with the parameter passed using the keyword. For example OSTYPE(`linux’) causes the file /usr/share/sendmail-cf/ostype/linux.m4 to be included. Any changes we make will have to be made in /etc/mail/sendmail.mc as we do not have write access to any of the files in /usr/share on the Westhost VPS platform.
Structure of sendmail.cf
It is important that you maintain the order of your configuration file. The general rules are that the order should be:
VERSIONID
OSTYPE
DOMAIN
FEATURE
local macro definitions
MAILER
LOCAL_RULE_*
LOCAL_RULESETS
There are a few exceptions to this rule. Local macro definitions which influence a FEATURE() should be done before that feature. For example, a define(`PROCMAIL_MAILER_PATH’, …) should be done before FEATURE(`local_procmail’).
Beware: MAILER declarations should always be at the end of the configuration file, and MAILER(`smtp’) should always precede MAILER(`procmail’), and MAILER(`uucp’).
Adding Comments
You can include comments in your file, but it is imperative that you do not include keywords such as define or FEATURE in a comment as m4 will expand them. (A full list of m4 keywords can be found here). If you want the comment to appear in sendmail.cf, then start it with the # character. If you just want the comment to appear in sendmail.mc, then start it with dnl. For example
# This comment will appear in sendmail.cf
dnl but this one will not
# The first part of this comment will dnl and the rest will not
dnl # but none of this comment will appear in sendmail.cf
Diversions
m4 controls the generated output using diversions.What this means is that the order of the input files is not necessarily that of the output file. To quote from the m4 manual
When you start using m4, output is written to diversion zero, which is the standard output. When m4 reaches the end of the input, it writes out the contents of all the diversions in numerical order.
Use PUSHDIVERT ( new diversion ) and POPDIVERT to change the current diversion and restore it. For example:
PUSHDIVERT(9)
dnl Change logging level
undefine(`confLOG_LEVEL')dnl
define(`confLOG_LEVEL',`9')dnl
POPDIVERT
Making your changes
As I said earlier, the preferred place for changes at Westhost is in the /etc/mail/sendmail.mc file. Lets say that we wanted to add some headers to incoming email. We would add
dnl 15Nov06 Add extra mail headers for spam checking
dnl The Sender Address Relative to the recipient
HX-Envelope-From: $g
dnl Recipient's username - needed to check bcc
HX-Envelope-To: $u
dnl The incoming protocol used
HX-Protocol: $r
A full list of the available macros ($g, $u etc) are available here or on page 42 of the Sendmail Installation and Configuration guide
Compiling your changes
Once your changes are complete, you need to convert them into something that sendmail can understand. I recommend that you redirect the output to a new file so that you can check for changes before going live.
m4 sendmail.mc >sendmail.new
diff sendmail.cf sendmail.new