Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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. So, I know the C# code is functional. We are not interested in using Microsoft Exchange Server as it is an overkill for us. Please help.
Posted
Updated 22-May-19 2:34am
v2

On Window 2008 R2 try using RegAsm from the 64Bit .NET folder if 32bit folder doesn't work for you.
 
Share this answer
 
Have you tried using the RegAsm from the 64bit directory of .NET, that worked for me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900