VBScript EventSink: Why doesn't this work?

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anders_hgAuthor Commented:
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
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anders_hgAuthor Commented:
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?


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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.