Solved

VBScript EventSink: Why doesn't this work?

Posted on 2003-10-28
6
582 Views
Last Modified: 2012-06-21
Hello,
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,
Anders.



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.Open
      Stm2.LoadFromFile Path
            
      Set iMsg2 = CreateObject("CDO.Message")
      Set iDsrc = iMsg2.GetInterface("IDataSource")
      iDsrc.OpenObject Stm2, "_Stream"
            
      Set LoadMessageFromFile = iMsg2
End Function
0
Comment
Question by:anders_hg
  • 2
6 Comments
 
LVL 1

Author Comment

by:anders_hg
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
/Anders.
0
 
LVL 8

Accepted Solution

by:
JasonBigham earned 250 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?

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317327
http://support.microsoft.com/default.aspx?scid=kb;en-us;317680&Product=exch2k

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

http://support.microsoft.com/?kbid=313404

... random link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/wsst_registering_an_event_sink.asp



0
 
LVL 1

Author Comment

by:anders_hg
ID: 9635234
Hello,
I think I registered the sink using
http://support.microsoft.com/default.aspx?scid=kb;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?

regards,
Anders.

0
 

Assisted Solution

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

Msg.DataSource.Save

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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now