In this article we will learn how to configure sendmail so that you can log “Subject” in /var/log/maillog as by default sendmail does not log Subject to maillog file.
This is really interesting. Business people many times are interested in getting mail log files analyzed. To analyse mail logs they need various field to appera in mail logs. e.g. “From”, “To”, “Subject” etc from the sent email. By default sendmail logs From and To fields but it does not log Subject field. In this article you will learn how to enable sendmail to log “Subject”.
- First of all take backup of your “sendmail.mc” and “sendmail.cf” files. Default location for those files is /etc/mail.
- Now open “sendmail.mc” in your favourite editor and add following lines in it and save it. I usually prefere to add it at boottom of file so you can easily identify your modifications.
R$* Press TAB Key $: $(log Subject: $1 $) $1
This last line is very crusial. after R$* press tab key as suggested. Then after $: press space key.
After log there is a space key, after Subject: there is a space key after $1 there is a space key. After closing bracket there is a space key before $1.
- Now you need to regenerate sendmail.cf file. use m4 macro to do so.
#m4 sendmail.mc > sendmail.cf
- Now restart sendmail and you verify your maillog file. You will see Subject line for each mail which is being sent from or relayed from your email server