Sendmail – Taking copies of all outgoing mails

If we need to take a copy of all outgoing mails, we have the following hack.

if you have installed sendmail from source .. create a file called copyuser.m4
in {Sendmail Source Dir}/cf/hack with the following content:
———— Cut Here ————–
divert(0)dnl
VERSIONID(`copyuser.m4′)dnl
ifdef(`_MAILER_smtp_’,,`errprint(`*** MAILER(smtp) must appear before copymail mailer’)’)dnl
LOCAL_CONFIG
CPNOCOPY
LOCAL_NET_CONFIG
R$+<@$+.NOCOPY.> $#esmtp $@$2 $:$1<@$2.>
R$+<@$+.> $#copymail $@nohostneeded $:$1<@$2.NOCOPY>
R$+<@$+> $#copymail $@nohostneeded $:$1<@$2.NOCOPY>

MAILER_DEFINITIONS
# Copy a message by sending it back to sendmail with an additional address:
# Here, the mail is sent to user mailbackup.
Mcopymail, P=/usr/sbin/sendmail, F=fmSDFMu,S=11/31,
R=ifdef(`_ALL_MASQUERADE_’, `21/31′, `21′),A=sendmail mailbackup $u

———— Cut Here ————–

then in ur sendmail.mc file add line
hack(`copyuser’)

Then generate the cf file and use it ( you should have created account called mailbackup where the backedup mail goes)