N Cosmin

N Cosmin

  • NA
  • 2
  • 0

Problems with Windows Service and Outlook

Mar 16 2006 9:38 AM

I'm new in C# programming ( only 1 month passed ) and i have an unsolved problem with outlook object initialisation.

Here is my problem:

I've written a windows application that is periodically verifying the Inbox folder from Microsoft Outloox ( within an interval of 10 secounds ). This application is working and it does exactly what it has to do.

The problem is that the same code putted in a windows service ( the declaration and initialisation of the Outlook Objects are the same in both cases ) seems not to be working, because the Outlook Object is not initialising corectly.

Here is the declaration and initialisation of the variables that are handling the Outlook Object:

//this goes to global declaration
public static Outlook.Application olOutlook = new Outlook.ApplicationClass();
public static Outlook.NameSpace olNS = olOutlook.GetNamespace("MAPI");
public Outlook.MailItem olMail = (Outlook.MailItem)olOutlook.CreateItem(Outlook.OlItemType.olMailItem);
public static Outlook.Folders olFolders = olNS.Folders;
public Outlook.Items olCustomFolderItems;

//this goes to the function that is collecting the mails from inbox
Outlook.MAPIFolder olInbox = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
olCustomFolderItems = olInbox.Items;


So..were i go wrong? I will apreciate any advice.
P.S. I've tried to put the collecting function in a Class Library (DLL),and it's still not working.