Log All Email for Sendmail in CentOS 5

Do you ever wanted to copy each and every incoming and outgoing email in Sendmail automatically to a single email acccount transparently? Thanks to Axel Reinhold’s logall.c module. Now, we can do it. In the below HOWTO, we will configure Sendmail to copy each and every incoming and outgoing email to an email account called “logall”.

Requirement: Sendmail, logall.c and CentOS 5

1. Please make sure the following are installed: -
cpp-4.1.1-52.el5.i386.rpm
elfutils-0.125-3.el5.i386.rpm
elfutils-libs-0.125-3.el5.i386.rpm
gcc-4.1.1-52.el5.i386.rpm
libgomp-4.1.1-52.el5.i386.rpm
rpm-build-4.4.2-37.el5.i386.rpm

2. Download the sendmail source rpm using the link below: -
http://mirrors.kernel.org/centos/5/os/SRPMS/sendmail-8.13.8-2.el5.src.rpm

3. Go to “Subject: Q4.20 — How can I automatically copy messages based on sender or recipient addresses?” in Sendmail.org website using the link below: -
http://www.sendmail.org/faq/section4.html#4.20

4. Download the Axel Reinhold’s logall.c module using the link below: -
http://www.freakout.de/logall.c

5. Install the sendmail source rpm using the command below: -
rpm -ivh sendmail-8.13.8-2.el5.src.rpm

6. Extract the sendmail source file using the command below: -
tar xvfz /usr/src/redhat/SOURCES/sendmail.8.13.8.tar.gz -C /tmp

7. Add the following line into this file /tmp/sendmail-8.13.8/sendmail/conf.c at line 1312 as below: -
#include "/tmp/logall.c"

8. Below is the partial content of /tmp/sendmail-8.13.8/sendmail/conf.c file: -
if (tTd(49, 1))
sm_dprintf("checkcompat(to=%s, from=%s)\n",
to->q_paddr, e->e_from.q_paddr);
#include "/tmp/logall.c"

9. Save the file and create a new sendmail archive using the command below: -
cd /tmp
tar cvfz sendmail.8.13.8.tar.gz sendmail-8.13.8

10. Backup the original sendmail archive using the following command below: -
cd /usr/src/redhat/SOURCES
mv sendmail.8.13.8.tar.gz /tmp/sendmail.8.13.8.tar.gz-ori

11. Copy the new sendmail archive into the installed source sendmail rpm using the following command below: -
cp sendmail.8.13.8.tar.gz /usr/src/redhat/SOURCES

12. Let’s build the sendmail binary package only from the spec file using the command below: -
cd /usr/src/redhat/SPECS/
rpmbuild -bb sendmail.spec

13. Let’s install the new sendmail binary package using the following command below: -
cd /usr/src/redhat/RPMS/i386
rpm --force -Uvh sendmail-8.13.8-2%{dist}.i386.rpm sendmail-cf-8.13.8-2%{dist}.i386.rpm

14. Edit the sendmail config file /etc/mail/sendmail.cf and add the following line below before this line “# level 10 config file format”: -
# logall.c
D{LogAll}/var/spool/mail/logall

15. Below is the partial content of /etc/mail/sendmail.cf file: -
# logall.c
D{LogAll}/var/spool/mail/logall

# level 10 config file format
V10/Berkeley

16. Restart the sendmail service using the following command below: -
service sendmail restart

17. Create the email accout called “logall” using the following command below: -
useradd logall
passwd logall
touch /var/spool/mail/logall
chown logall:logall /var/spool/mail/logall

18. Let’s send an email to a user using the following command below: -
echo "Test" | mail -s "TEST" wlsiew

19. Let’s check the content of the file /var/spool/mail/logall using the following command below: -
cat /var/spool/mail/logall

20. Below is the content of /var/spool/mail/logall file: -
From root Wed Sep 12 20:37:13 2007
Return-Path: <g>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.8/8.13.8) with ESMTP id l8CDbDAV008813
for <wlsiew@localhost.localdomain>; Wed, 12 Sep 2007 20:37:13 +0800
Full-Name: root
Received: (from root@localhost)
by localhost.localdomain (8.13.8/8.13.8/Submit) id l8CDbDR2008812
for wlsiew; Wed, 12 Sep 2007 20:37:13 +0800
Date: Wed, 12 Sep 2007 20:37:13 +0800
From: root <root@localhost.localdomain>
Message-Id: <200709121337.l8CDbDR2008812@localhost.localdomain>
To: wlsiew@localhost.localdomain
Subject: TEST
X-Logged: Logged by localhost.localdomain as l8CDbDAV008813 at Wed Sep 12 20:37:13 2007

Test

You can now begin to use the log all email feature.

Source: Sendmail

If you found these helpful, please contribute to help:

About wingloon

I am Linux engineer attempting to decode my knowledge through blogging in the World Wide Web. I will share my knowledge as much as possible about Linux (what I know best) and technology in general to all my readers.