Guest
|
Posted:
Mon Aug 08, 2005 8:58 am Post subject:
Async OnMessageSubmission Event Sink in VB.Net |
|
|
Hey all,
I'm attempting to create an asynchronous SMTP event sink in VB.Net,
which I hope to use for Spam and Virus scanning. Currently it just
creates a new thread which calls IMailTransportNotify.Notify with the
provided context, but IIS simply crashes when this happens for the
second time (first one goes through fine)
In the Event Sink class...
<GuidAttribute("46C96FF0-5C90-1280-8171-3C604E429C33"),
ComVisibleAttribute(True)> _
Public Class SinkX
Implements IMailTransportSubmission, IEventIsCacheable
Sub IsCacheable() _
Implements IEventIsCacheable.IsCacheable
End Sub
Public Sub OnMessageSubmission(ByVal pIMailMsg As MailMsg, ByVal
pINotify As IMailTransportNotify, ByVal pvNotifyContext As
System.IntPtr) _
Implements IMailTransportSubmission.OnMessageSubmission
Dim MyProcessor As New Processor(pIMailMsg, pvNotifyContext,
pINotify)
Try
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf NewThread),
MyProcessor)
Throw New COMException("Processing...", &H103)
Catch NewEx As Exception
LogEvent("Exception " & NewEx.ToString())
Finally
LogEvent("Message " & MyProcessor.ID & " was sent on")
End Try
End Sub
Private Sub NewThread(Data As Object)
CType(Data, Processor).Start()
End Sub
End Class
In the Processor class...
Friend Class Processor
Private Context As System.IntPtr
Private Notify As IMailTransportNotify
Private MyComMessage As MailMsg
Public ID As Integer
Public Sub New(NewMessage As MailMsg, NewContext As System.IntPtr,
NewNotify As IMailTransportNotify)
Context = NewContext
Notify = NewNotify
MyComMessage = NewMessage
ID = NewID() ' Short function that simply counts up from Zero
End Sub
Public Sub Start()
Notify.Notify(0, Context)
LogEvent("Message " & ID & " was notified")
End Sub
End Class
My output log file looks like this...
Message 0 was sent on
Message 1 was sent on
Message 0 was notified
Message 1 was notified
It crashes straight afterwards, and I cannot work out why! Does Notify
not work properly from managed code? Is it something to do with using
VB.Net, should I switch to C#?
I'm using the Interop DLL available in the Manage SMTP Sink example on
MSDN, and registering it with...
regasm TestSink.dll /tlb:TestSink.tlb /codebase
cscript smtpreg.vbs /add 1 OnTransportSubmission TestSink
"TestSink.SinkX" "mail from=*" 28001
I really don't want to implement it as a synchronous sink, because the
process of scanning could take a while and other messages will be
forced to wait. Can anyone help me out?
Thanks
Daniel
|
|
Guest
|
Posted:
Thu Aug 11, 2005 7:00 am Post subject:
Re: Async OnMessageSubmission Event Sink in VB.Net |
|
|
It appears that Notify is returning 'ArgumentOutOfRange' for some
reason, and IIS was crashing because there was no exception handling.
This gets me no closer to fixing it though, because there is absolutely
NO documentation on using this function other than its definition in
MSDN. Not a single mention of it being used on the Internet. Extremely
frustrating!
I'm returning Zero, which is S_OK, and the Context it requested... I
don't know what's wrong!
Daniel
AlphaGremlin@gmail.com wrote:
| Quote: | Hey all,
I'm attempting to create an asynchronous SMTP event sink in VB.Net,
which I hope to use for Spam and Virus scanning. Currently it just
creates a new thread which calls IMailTransportNotify.Notify with the
provided context, but IIS simply crashes when this happens for the
second time (first one goes through fine)
In the Event Sink class...
GuidAttribute("46C96FF0-5C90-1280-8171-3C604E429C33"),
ComVisibleAttribute(True)> _
Public Class SinkX
Implements IMailTransportSubmission, IEventIsCacheable
Sub IsCacheable() _
Implements IEventIsCacheable.IsCacheable
End Sub
Public Sub OnMessageSubmission(ByVal pIMailMsg As MailMsg, ByVal
pINotify As IMailTransportNotify, ByVal pvNotifyContext As
System.IntPtr) _
Implements IMailTransportSubmission.OnMessageSubmission
Dim MyProcessor As New Processor(pIMailMsg, pvNotifyContext,
pINotify)
Try
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf NewThread),
MyProcessor)
Throw New COMException("Processing...", &H103)
Catch NewEx As Exception
LogEvent("Exception " & NewEx.ToString())
Finally
LogEvent("Message " & MyProcessor.ID & " was sent on")
End Try
End Sub
Private Sub NewThread(Data As Object)
CType(Data, Processor).Start()
End Sub
End Class
In the Processor class...
Friend Class Processor
Private Context As System.IntPtr
Private Notify As IMailTransportNotify
Private MyComMessage As MailMsg
Public ID As Integer
Public Sub New(NewMessage As MailMsg, NewContext As System.IntPtr,
NewNotify As IMailTransportNotify)
Context = NewContext
Notify = NewNotify
MyComMessage = NewMessage
ID = NewID() ' Short function that simply counts up from Zero
End Sub
Public Sub Start()
Notify.Notify(0, Context)
LogEvent("Message " & ID & " was notified")
End Sub
End Class
My output log file looks like this...
Message 0 was sent on
Message 1 was sent on
Message 0 was notified
Message 1 was notified
It crashes straight afterwards, and I cannot work out why! Does Notify
not work properly from managed code? Is it something to do with using
VB.Net, should I switch to C#?
I'm using the Interop DLL available in the Manage SMTP Sink example on
MSDN, and registering it with...
regasm TestSink.dll /tlb:TestSink.tlb /codebase
cscript smtpreg.vbs /add 1 OnTransportSubmission TestSink
"TestSink.SinkX" "mail from=*" 28001
I really don't want to implement it as a synchronous sink, because the
process of scanning could take a while and other messages will be
forced to wait. Can anyone help me out?
Thanks
Daniel |
|
|