SMTP Event Sinks in Windows 2008 R2

smtpwindows-server-2008

We use a 3rd party software to send Bulk Emails. The software does not provide options to add Email addresses in BCC. However, as per Compliance Rules, it is necessary for us to add a BCC address to every Email sent. Till now, we used to relay all the Emails from that software to an intermediate server having SMTP service installed in it. We deployed a VB6 DLL on that server which functioned as an SMTP Event Sink and it ran every time the "OnArrival" event of the SMTP service was fired. The DLL added the BCC address to the mail.
Every thing was running fine till now. Now, we have to upgrade those servers to Windows Server 2008 R2. I have re-written the VB6 Event Sink in C#. The code is like this:

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using ADODB;
using CDO;
using SEOLib;

namespace OnArrivalSink
{
 [Guid("8E9B5A44-ADC3-4752-9CF6-C5333A6B17CF")]
 public class CatchAll : ISMTPOnArrival, IEventIsCacheable
 {
    void IEventIsCacheable.IsCacheable()
    {
        //This will return S_OK by default
    }

    void ISMTPOnArrival.OnArrival(Message msg, ref CdoEventStatus eventStatus)
    {
        try
        {
            ProcessMessage(msg);
        }
        catch (Exception e)
        {
            string errorInfo = "ERROR MESSAGE: " + e.Message + "\n" +
                "INNER EXCEPTION: " + e.InnerException + "\n" +
                "SOURCE: " + e.Source + "\n" +
                "STACK TRACE: " + e.StackTrace + "\n";

            //Write to Event Log
            EventLog evtLog = new EventLog();
            evtLog.Source = "OnArrivalSink";
            evtLog.WriteEntry(errorInfo, EventLogEntryType.Error);
        }
        eventStatus = CdoEventStatus.cdoRunNextSink;
    }

    private void ProcessMessage(IMessage msg)
    {
        //Get the list of recipients that the message will be actually delivered to
        string recipientList = msg.EnvelopeFields["http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist"].Value.ToString();

        //Add a recipient in BCC form
        recipientList = recipientList + "SMTP:john.doe@xyz.com;";
        msg.EnvelopeFields["http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist"].Value = recipientList;        
        msg.EnvelopeFields.Update();
        msg.DataSource.Save();
    }
  }

}

The DLL generated by the above code was registered using RegAsm.exe and it was registered successfully. The DLL was bound with the SMTP "OnArrival" event using a VBScript provided by Microsoft and that too happened without any issues.
However, the DLL is not working at all. I tried logging every step but it's as if the DLL is not functioning at all. It works fine in a Windows XP machine.
We are not interested in using Microsoft Exchange Server as it is an overkill for us.
Please help.

Best Answer

Some designer at MS had the bright idea that the registration routines should return indicating success even though the SMTP service no longer uses 'Event Sinks' in IIS7+.

You'll have to rewrite your "filter" as a Transport Event Sink. It's similar, so it shouldn't take too long.

Related Topic