I don't know for sure, but I'd try putting a Guid attribute on the class
like:

[Guid("00000000-0000-0000-0000-000000000000")]
public class SmtpWatcher : CDO.ISMTPOnArrival {

and after registering the assembly, putting it into the GAC like

gacutil /i SMTPWatcherLib.dll

which will allow it to be found regardless of the directory of the calling
application.

Also, I'm assuming the typo of SMTP in the following:

> I tried using cscript smtpreg.vbs /add 1 onarrival MySink
> STMPWatcherLib.SmtpWatcher "mail from=*",

is in the e-mail only, not what you were actually trying.

HTH,
Jim

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]]On Behalf Of Hein, Richard
Sent: Sunday, September 22, 2002 8:19 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Handling SMTPOnArrival COM events


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.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to