Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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?;EN-US;Q317327;en-us;317680&Product=exch2k

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;EN-US;Q317327

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

705 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