Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer
1  
That's what I did. I used CDO to re-write the sink. See "using CDO;" in my code? But the point of interest in your answer is that IIS 7 does not use SMTP event sinks any more. Can you share some official link stating this? If IIS 7 does not use SMTP Event Sinks anymore then my sink will not work. So do you have any alternatives? –  user171667 Apr 29 '13 at 14:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.