We are trying to watch an Exchange Server for new messages and extract attachments arriving. I looked at the documentation for CDO, and found the ISMTPOnArrival interface. Following the guidelines in the .NET SDK for advance COM Interop, I used tlbimp to create a wrapper for CDO. What I came up with was the following code:
using System; using System.IO; using System.Runtime.InteropServices; using CDO; using ADODB; namespace SMTPWatcherLib { /// <summary> /// Summary description for Class1. /// </summary> public class SmtpWatcher : CDO.ISMTPOnArrival { static private CDO.SMTPConnectorClass smtpCon = null; public SmtpWatcher() { } public static void Main() { SmtpWatcher smtpWatcher = new SmtpWatcher(); smtpWatcher.Run(); Console.Read(); } public void Run() { smtpCon = new SMTPConnectorClass(); CDO.ISMTPOnArrival_OnArrivalEventHandler SMTPMessageArrived = new CDO.ISMTPOnArrival_OnArrivalEventHandler(OnArrival); smtpCon.OnArrival += SMTPMessageArrived; } public void OnArrival(CDO.Message Msg, ref CDO.CdoEventStatus EventStatus) { IBodyParts parts = Msg.Attachments; FileStream logStream = File.Create(@"C:\test\OnArrivalLog.txt"); StreamWriter writer = new StreamWriter(logStream); try { writer.WriteLine("From: " + Msg.From); writer.WriteLine("Subject: " + Msg.Subject); foreach(IBodyPart part in parts) { part.SaveToFile(part.FileName); } EventStatus = CdoEventStatus.cdoRunNextSink; } catch { } finally { logStream.Flush(); writer.Flush(); logStream.Close(); writer.Close(); } } } } I used RegAsm to register the assembly, but what now? It's not doing a thing. I tried using cscript smtpreg.vbs /add 1 onarrival MySink STMPWatcherLib.SmtpWatcher "mail from=*", and it appears to register the bindings, but nothing happens. I also tried making this just a class library, but no effect. I don't know much about COM, so please help me out here. Thanks a lot, Richard A. Hein Level Platforms Inc. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.