Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Win2008-R2 SMTP
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. 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 29-Apr-13 22:59pm
Edited 29-Apr-13 23:04pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

On Window 2008 R2 try using RegAsm from the 64Bit .NET folder if 32bit folder doesn't work for you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have you tried using the RegAsm from the 64bit directory of .NET, that worked for me
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100