本文介绍了SMTP事件接收器是否可以在Windows Server 2008 R2中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用第三方软件发送批量电子邮件。该软件不提供在BCC中添加电子邮件地址的选项。但是,根据合规性规则,我们有必要为每个发送的电子邮件添加BCC地址。到目前为止,我们曾经将该软件的所有电子邮件转发到安装了SMTP服务的中间服务器。我们在该服务器上部署了一个VB6 DLL,它作为SMTP事件接收器运行,每次触发SMTP服务的OnArrival事件时它都会运行。 DLL将BCC地址添加到邮件中。到目前为止,每件事都运行良好。现在,我们必须将这些服务器升级到Windows Server 2008 R2。我用C#重写了VB6事件接收器。代码如下:



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:[email protected];";
        msg.EnvelopeFields["http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist"].Value = recipientList;
        msg.EnvelopeFields.Update();
        msg.DataSource.Save();
    }
  }





上面代码生成的DLL是使用RegAsm.exe注册的,它已经注册成功。 DLL使用Microsoft提供的VBScript与SMTPOnArrival事件绑定,并且也没有任何问题。但是,DLL根本不起作用。我尝试记录每一步,但就好像DLL根本不起作用。 它在Windows XP机器上运行良好。所以,我知道C#代码是有效的。我们对使用Microsoft Exchange Server不感兴趣,因为它对我们来说太过分了。请帮忙。



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.

推荐答案



这篇关于SMTP事件接收器是否可以在Windows Server 2008 R2中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:53