Log All Email for Sendmail in CentOS 5

11 Comments

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:

11 Comments (+add yours?)

  1. dmitry
    Sep 26, 2007 @ 21:53:28

    your tutorial is full of errors and typos

  2. simonz
    Sep 27, 2007 @ 22:17:05

    cool bro, its works. I tried on my server and it run perfectly…good job bro.

  3. simonz
    Sep 27, 2007 @ 22:24:31

    bro, for those example can you remove the numbering and put as eg. as not to confused newbies and thought as steps that need to be followed. Thanks.

  4. wingloon
    Sep 27, 2007 @ 22:45:59

    dmitry, can you tell me the errors and typos?

  5. dmitry
    Sep 28, 2007 @ 01:05:41

    there are some paths incorrect, for example ‘i386′ in invalid on my 64-bit system

    also this line “rpm –force -Uvh”

    asks the rpm to update and sometimes it fails silently (centos 64 bit) – i had to remove sendmail completely and all its dependencies and then use “-Ivh” options instead to install – it works then.

  6. Wing Loon
    Sep 28, 2007 @ 17:56:21

    dmitry, thank you for your reply, :)

    i386 is only valid in a 32-bit system whereas you need x86_64 for your 64-but system.

    this is strange… the “rpm –force -Uvh” works great for my system, :)

  7. simonz
    Sep 28, 2007 @ 18:53:16

    bro, you need to use “–force” instead of “-force”
    it works great for me too… :)

  8. Anshul
    Aug 27, 2008 @ 13:35:51

    hi frnds,

    I’ve tried logall.c it works perfectly fine.It logs all incoming & Outgoing Mails

    but there r some issues like it makes multiple copies of a single mail if the mail is send to different reciepient like To|Cc|Bcc.
    it will the same no of copies of a mail depending upon the ids entered in To|cc|Bcc fields.

    It also doesn’t copy mails tagged as Spam in the subject. May be this could be bcoz of X-Spam headers.

    if any one has some solution to it plz reply.

    Anshul

  9. David Keegel
    Jun 27, 2011 @ 13:53:27

    Before step 12, you could edit /usr/src/redhat/SPECS/sendmail.spec and change
    the Release line,
    from:
    Release: 2%{?dist}
    to:
    Release: 2_logall%{?dist}

    That will mean the generated sendmail rpm is called something like sendmail-8.13.8-2_logall.el5.i386.rpm instead of sendmail-8.13.8-2.el5.i386.rpm.
    That means you won’t need to use –force when installing your new rpm.

    And might also help you to remember that you have a special version of sendmail installed, which is important if you are thinking of updating sendmail later.

  10. David Keegel
    Jun 27, 2011 @ 14:03:16

    You could also use
    # rpm -Fvh /usr/src/redhat/RPMS/i386/sendmail*.rpm
    to upgrade any sendmail* rpms that you already have installed, but not install any new sendmail* rpms. (Assuming that you don’t have any old sendmail*.rpm’s lying around in that directory. And substitute `uname -i` for i386 if you have a 64-bit platform, etc.)