Go Premium for a chance to win a PS4. Enter to Win


VBScript EventSink: Why doesn't this work?

Posted on 2003-10-28
Medium Priority
Last Modified: 2012-06-21
I am trying out, what I thought to be, a simple event sink. I load a new message from an
existing file and want to replace the old incoming message with the new one.

Everything looks allright. sTempValue has the new subject, but when I receive the mail
its the old one. What am I missing here?

thank you,

Sub ISMTPOnArrival_OnArrival(Msg, EventStatus)

      '// Load a new message
      Set fMsg = LoadMessageFromFile("c:\test.mai")

      '// Set old message to new message
      Set Msg = fMsg

      sTempValue = Msg.Subject '// Its the new one!!

End Sub

Function LoadMessageFromFile(Path) 'As Message
      On Error Resume Next

          Dim Stm2  'As ADODB.Stream
          Dim iMsg2 'As CDO.Message
          Dim iDsrc 'As CDO.IDataSource

      Set Stm2 = CreateObject("ADODB.Stream")
      Stm2.Charset = "ascii"
      Stm2.LoadFromFile Path
      Set iMsg2 = CreateObject("CDO.Message")
      Set iDsrc = iMsg2.GetInterface("IDataSource")
      iDsrc.OpenObject Stm2, "_Stream"
      Set LoadMessageFromFile = iMsg2
End Function
Question by:anders_hg
  • 2

Author Comment

ID: 9633408
additional info:
I found the msdn Q273233 article describing the problem,
but this does not seem to apply to my problem as I can
successfully change the recipient list from the EnvelopeFields.

thank you

Accepted Solution

JasonBigham earned 1000 total points
ID: 9634499
I don't see why the code would care, but do you have to load a file with an EML extension, not an MAI extension?

 Set fMsg = LoadMessageFromFile("c:\test.mai")

 Set fMsg = LoadMessageFromFile("c:\test.eml")

Additionally, not sure on this, but does the event sink only work for incoming/outgoing SMTP (internet) email? That is, how did you register it like one of these articles?


Or was it with this ine instead (this last one may assist you as well)?


... random link


Author Comment

ID: 9635234
I think I registered the sink using

am not at work, so I cant look it up, but 80% sure of it. otherwise I'll get
back to you on this one.

regarding the mail extension, that should not really matter, does it?
I can read all mail fields including attachments through the CDO.Message
interface using the LoadMessageFromFile function.
I can also use the loaded mail and place it in an exchange folder.
What I actually do is to take the incoming mail, save it to a text file,
do a SpamAssassin on it and load it back to iMsg2.

The strange things is that I can read all the Msg properties fine, which
are the same as the fMsg mail (after Set Msg = fMsg), but it seems that
those fields dont get saved leaving the sink. The recipientlist alteration
(using the envelopefields(recip_list) property), though, does somehow
get saved as the mail is sent to the right people.

strange. does this give some new light on the problem?



Assisted Solution

jbiggs earned 1000 total points
ID: 9884961
try placing this line in your code:


Put it after:

Set Msg = fMsg

Because if you don't then you are only modifying the SMTP message in memory.  You have to save it back to the queue after you are finished processing it.

John Biggs
Network Engineer
Trammell Crow Residential
jbiggs at tcresidential dot com

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question