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

x
?
Solved

VBScript EventSink: Why doesn't this work?

Posted on 2003-10-28
6
Medium Priority
?
589 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
4 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 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?

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 1000 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

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