Thursday, September 23, 2010

Sendmail - Sandwich Mode How TO

It is used in scenario when we want sendmail to listen on port 25 which have anti-relay feature instead of any SMTP Proxy that many Anti-Virus or Anti-Spam used like TrendMicro Interscan or IMSS (Interscan Messaging Security Suite), because it don’t have any Anti-relay or SMTP Auth features.

This document describes the procedures to configure sendmail to use InterScan as an anti-virus solution and still benefit from sendmail’s anti-relay feature.

The following instructions provide the details to setup IMSS and sendmail on a single Unix box. Only one sendmail daemon is run alongside IMSS.

This configuration has a performance hit when IMSS deliver’s mail after scanning. The performance hit occurs when IMSS starts the sendmail program to do the mail delivery. The performance hit is directly proportional to the time and resources required to execute a sendmail program as this is exactly what IMSS is doing. For heavy mail traffic, this configuration will not work well, for that we can have separate machine for each instance like one machine for Incoming Sendmail which delivers mail to IMSS running on same or different machine which in turn delivers to Outgoing Sendmail (Delivery Mode) running on different machine.

We recommend pre-spawning another sendmail daemon and have it listen to port 19000. Then have IMSS running on port 18000 does the Anti-Spam and Anti-Virus check and then connect to delivery sendmail on port 19000 to deliver mail.

Sendmail daemon and InterScan on one box

The following illustration depicts the scenario of running a sendmail daemon and InterScan on the same Unix box.

Note: Port 18000 is an arbitrary port number. Please select a free port when doing the configuration below. Port 25 is the standard SMTP port. This should not be changed.

The instructions to configure the mail daemons for this configuration are as follows.

Configure sendmail,
1.      Make a copy of file called
2.      Change the A option in for Msmtp, Mesmtp, Msmtp8, and Mrelay from “IPC $h” to “IPC localhost 18000” where 18000 is an arbitrary free port on box_1.
3.      Add the k flag to the F option for Msmtp, Mesmtp, Msmtp8, and Mrelay in

At this point the changes for Msmtp (as an example) look as follows:
Msmtp,                   P=[IPC], F=mDFMuX, S=11/31, R=21, E=\r\n, L=990,
                                A=IPC $h
Msmtp,                   P=[IPC], F=kmDFMuX, S=11/31, R=21, E=\r\n, L=990,
                                A=IPC localhost 18000

4.      Replace the local mailer with [IPC] for Mlocal in
5.      Change the A option to “IPC localhost 18000” for Mlocal in
6.      Add the k flag to the F option for Mlocal in

At this point the changes for Mlocal look as follows:
Mlocal,                  P=/usr/lib/mail.local, F=lsDFMAw5:/|@qfSmn9, S=10/30, R=20/40,
                                A=mail.local -d $u
Mlocal,                  P=[IPC], F=klsDFMAw5:/|@qSmn9, S=10/30, R=20/40,
                                A=IPC localhost 18000

IMPORTANT: Make sure the F option of Mlocal does not include the ‘f’ flag. This flag is standard on Solaris 7 distribution of sendmail and needs to be removed.

Configure the delivery sendmail used by InterScan,
7.      Change the Pid of the delivery Sendmail in

O PidFile=/var/run/
O PidFile=/var/run/

8.      Change the mail queue to a different directory in

O QueueDirectory=/var/spool/mqueue
O QueueDirectory=/var/spool/mqueuedelivery

9.      Create the directory /var/spool/mqueuedelivery and make sure it has the same ownership and permission as the original in /var/spool/mqueue.
10.  Add the k flag to the F option for Mlocal, Msmtp, Mesmtp, Msmtp8, and Mrelay in

Now there are two configuration one for new TrendMicro IMSS version and other for old TrendMicro Interscan version so out of these we can chose and configure one of them depending upon your setup.

Configure IMSS

11.  Copy the original IMSS configuration file using following command.

cp /opt/trend/imss/imss.ini /opt/trend/imss/

12.  Change all these entry as stated below :-

vi /opt/trend/imss/imss.ini
            smtp_greeting_msg=IMSS SMTP proxy
            #smtp_allow_client_ip=addr: addr:

13.  Start the sendmail and IMSS service and check using the following command :-

          /etc/rc.d/init.d/sendmail stop
/etc/rc.d/init.d/sendmail stop

/usr/sbin/sendmail -bd -C/etc/mail/
          /usr/sbin/sendmail -bd -C/etc/mail/

/etc/rc.d/init.d/S99ISIMSS stop
/etc/rc.d/init.d/S99ISIMSS start

Now check the Incoming Sendmail instance

telnet 25

Now check the Outgoing instance of Sendmail (Delivery Mode)

telnet 19000

Now check the IMSS instance :-

telnet 18000

14.  Edit the /etc/init.d/sendmail to start both instance of Sendmail for Incoming and Outgoing delivery of Mail.

vi /etc/init.d/sendmail

            Edit these line in that start section of the script
daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
$([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG
#daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
#$([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG
            daemon /usr/sbin/sendmail -bd -C/etc/mail/
daemon /usr/sbin/sendmail -bd -C/etc/mail/

            Add these line in that stop section of the script to stop two instances of sendmail.

            echo -n $"Shutting down Sendmail Delivery: "
killproc sendmail
killproc sendmail

Check the script is working or not using following command.

/etc/init.d/sendmail stop
/etc/init.d/sendmail start

Configure InterScan

15.  Make sure the sendmail version of ISVW is installed and not the plugin version.
16.  Edit intscan.ini and change the InterScan SMTP service port to 18000.
17.  In intscan.ini, change the original SMTP server location to include “-C /etc/mail/” where the file is assumed to be in /etc/mail.

Under [smtp],
original=/usr/lib/sendmail -bs
original=/usr/lib/sendmail –bs –C/etc/mail/

18.  Restart InterScan SMTP by “/etc/iscan/sendmail”.
19.  Restart a new sendmail daemon to process the new mail queue by “/usr/lib/sendmail –q1h –C/etc/mail/”
20.  Restart sendmail to handle SMTP traffic on port 25 by “/usr/lib/sendmail –bd –q1h”.

Note: although there is a second sendmail daemon running, this daemon’s only responsibility is to process any mail that has been queued up. If this second daemon is not running, then the user will need to manually and periodically flush the queue.

The S88sendmail rc script must be modified to correctly start the mail servers:
1.      The start script should now start 3 daemons (started in steps 12, 13, and 14).

Under start section of the script,
/etc/iscan/sendmail; /usr/lib/sendmail –q1h
/etc/iscan/sendmail; /usr/lib/sendmail –q1h –C/etc/mail/; /usr/lib/sendmail –bd –q1h

Note that this document comes without warranty of any kind. But every effort has been made to provide the information as accurate as possible. I welcome emails from any readers with comments, suggestions, and corrections at webmaster_at

Copyright © 2012 LINUXHOWTO.IN


  1. Good Job Pankaj......

  2. Hi Pankaj,

    If I built IMSS in other server, which configuration in I need to change?

  3. How to read and understand Sendmail 8.14 log files

    1. Jun 13 18:32:38 serv1 sendmail[7441]: q5DMWcS2007441: from=rohit, size=315, class=0, nrcpts=1, msgid=<20120613223237.GA7436'#'>, relay=root'#'localhost
      Jun 13 18:32:38 serv1 sm-mta[7442]: q5DMWcDD007442: from=, size=466, class=0, nrcpts=1, msgid=<20120613223237.GA7436'#'>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain []
      Jun 13 18:32:38 serv1 sendmail[7441]: q5DMWcS2007441: to=rohit'#', ctladdr=rohit (502/505), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30315, relay=[] [], dsn=2.0.0, stat=Sent (q5DMWcDD007442 Message accepted for delivery)
      Jun 13 18:32:38 serv1 sm-mta[7443]: q5DMWcDD007442: to=, ctladdr= (502/505), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30663, dsn=2.0.0, stat=Sent
      Jun 13 18:32:38 Date of Mail received to the Mail Transfer Agent
      serv1 = Hostname
      sm-mta[7443]: = MTA or Application Name with PID for the Mai
      q5DMWcDD007442: = Queue ID
      from= (Sender Address)
      to= (Reciepient Address)
      size=315 Size in Bytes
      nrcpts=1 Number of Recepients
      msgid=<20120613223237.GA7436'#'> = Message ID (Unique of every Mail)
      proto=ESMTP = Protocol Used
      daemon=MTA = Application Handler In Sendmail it could be MSP or MTA
      relay=localhost.localdomain [] = Mail relayed to the next Destination Server / Recipient Server
      dsn=2.0.0 = Delivery Status Notification, It can be 2.x.x, 4.x.x, 5.x.x Where 2.x.x is Successfully Sent, 4.x.x Is Mail Temporarily Deferred, 5.x.x stands for Permanent Failure
      stat=Sent = Status of the Message. Values Sent,Deferred,Bounced
      q5DMWcDD007442 Message accepted for delivery = Unique ID on which the mail was delivered on the targeted server