How to Display Email Subject in Sendmail Log on CentOS 7

Sendmail is a default mail server in some Linux distro like CentOS that is often used by system administrators to email and its use is easy. Unfortunately, by default sendmail log (in /var/log/maillog) do not display the subject, so sysadmins will have difficulties if they have to search for an email based on the title in the log. This article will explain how to display titles in the log in CentOS 7.
For example, I want to email like this:

If we see in sendmail log in /var/log/maillog, there is no subject for this email:
sendmail log

So if we want to display subject in the log, then follow the following commands:
# cd /etc/mail
# cp sendmail.mc sendmail.mc.ori
# yum install sendmail-cf

After that, we configure the sendmail.mc file by adding the script below into the file:

LOCAL_CONFIG
Klog syslog
HSubject: $> + CheckSubject

LOCAL_RULESETS
SCheckSubject
R$* $: $ (log Subject: $1 $) $1

The most important part of the script above is on the last line (look at line 7). If we are wrong in this line, then the subject will not appear in the log. After typing R$*, press Tab key, then writes $: then press space and write $. After that pressing space after typing Subject: then write $1, space back then write $) keep spaces again and write $1.

In brief, the explanation can be written:
After that restart sendmail by:
# m4 sendmail.mc > sendmail.cf
# systemctl restart sendmail

Try to send email again using sendmail and should the email title can be displayed in the log.
sendmail log

You can see the picture above that subject display in the log.

References:
platonic.techfiz.info

Leave a Reply

Your email address will not be published. Required fields are marked *