Phew, Long title eh.
Basically I need to intercept Emails using the SMTP Sevice and the OnArrival event sink. I've come up with the following simple test app :-
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
Public Overridable Sub OnArrival(ByVal Msg As CDO.Message, ByRef EventStatus As CDO.CdoEventStatus)
EventStatus = CDO.CdoEventStatus.cdoSkipRemainingSinks
Dim sr As StreamWriter = File.AppendText("C:\Logfile.txt")
sr.WriteLine("Event Sink fired")
I tick the 'Register for COM Interop' box under properties->configuration properties->build and DLL seems to compile ok with no errors.
I then registered the COM Class using Regasm :-
Regasm ClassLibrary.dll /codebase
and finally point the SMTP service to the event sink with the smtpreg script provided by microsoft :-
cscript smtpreg.vbs /add 1 OnArrival ClassLibrary ClassLibrary.ComClass "mail from=*"
The code in the event sink isn't run and nothing appears in the log file, but the smtp service does seem to open the DLL and use it because I can't access the DLL file after I send a test message to the smtp service until I reboot.
I assuming that my DLL is getting called but for some reason nothing happens after that. Can anyone see what I'm doing wrong?
I realise this is a tough one so I've assigned max points to the question.