如何在 Visual Basic 脚本中向出站 SMTP 邮件添加免责声明

概要

本文分步介绍如何使用 SMTP 传输事件接收器向出站 SMTP 电子邮件添加“免责声明”。

返回页首

创建事件接收器

要创建事件接收器,请将以下代码粘贴到一个新的文件中并将其另存为 EventSinkScript.vbs:
<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
   TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "Sample Disclaimer added in a VBScript."
   HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>Sample Disclaimer added in a VBScript."

   If Msg.HTMLBody <> "" Then
      'Search for the "</body>" tag and insert our discliamer before that tag.
      pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
      szPartI = Left(Msg.HTMLBody, pos - 1)
      szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
      Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
   End If

   If Msg.TextBody <> "" Then
      Msg.TextBody = Msg.TextBody & vbCrLf & TextDisclaimer & vbCrLf
   End If

   'Commit the content changes to the transport ADO Stream object.
   Msg.DataSource.Save ' Commit the changes into the transport Stream

   pEventStatus = cdoRunNextSink
End Sub
</SCRIPT>

注册事件接收器

要注册事件接收器,请使用随 Exchange SDK 一起安装的 Smtpreg.vbs 文件。在命令提示符处,浏览到 ...\Exchange SDK\SDK\Support\CDO\Scripts 文件夹,并键入以下命令(确保 EventSinkScript.vbs 的路径正确):
cscript smtpreg.vbs /add 1 onarrival SMTPScriptingHost CDO.SS_SMTPOnArrivalSink "mail from=*@your-domain-here.com"
cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingHost Sink ScriptName "C:\EventSinkScript.vbs"
如果此命令成功执行,您将收到由脚本生成的成功消息。

要取消注册此事件,请键入以下内容:
cscript smtpreg.vbs /remove 1 OnArrival SMTPScriptingHost
有关使用 Smtpreg.vbs 注册事件的更多信息,请参见下面 MSDN 网站上的“Managing Event Bindings”(管理事件绑定)主题:

测试事件接收器

要测试接收器,请向您组织外的一个 SMTP 收件人发送一封电子邮件。收件人应当收到一个在末尾添加了“免责声明”的经修改的邮件。

注意:如果您使用一个诸如 Microsoft Outlook 这样的 MAPI 客户端发送电子邮件,收件人将接收不到修改的邮件。这是因为在电子邮件触发 SMTP 传输事件时,使用 MAPI 提交的邮件不是 SMTP 格式。因此,由事件代码做出的更改不能持续。

返回页首
 

参考

有关其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章:
273233 PRB:CDOEX:在 CDO SMTP 事件接收器中不能更改 MAPI 邮件内容
返回页首
 

这篇文章中的信息适用于:
Microsoft Exchange Server 2003 Enterprise Edition
Microsoft Exchange Server 2003 Standard Edition
Microsoft Exchange 2000 Server 标准版
Microsoft Windows Server 2003 Standard Edition
the operating system: Microsoft Windows 2000
Collaboration Data Objects for Exchange 2000 6.0
Microsoft Collaboration Data Objects 2.0
 
关键字: 
kbhowtomaster KB317680
,

分享到