none
C# several exchange accounts through Outlook RRS feed

  • Question

  • Hi,

    I'm trying to work with several exchange accounts through Outlook 2007 with C# for VS 2008.

    Saddly our administrator had disabled EWS which worked well...

    Do you know a way to work with them?

    I can see every Exchange accounts in Outlook but when I try to read them it only works for the main exchange user (and all unReadCount value are false).

    I use the following code :

    namespace Outlook2007
      {
      class Program
        {
        public static void DisplayExchangeAccounts()
          {
          Outlook.Application applicationOutllok2007 = new Microsoft.Office.Interop.Outlook.ApplicationClass();
          Outlook.NameSpace ns = applicationOutllok2007.GetNamespace("MAPI");
          Outlook.Folders folders = ns.Folders;
    
          foreach (Outlook.MAPIFolder folder in folders)
            {
            Console.WriteLine(folder.Name + " (" + folder.UnReadItemCount + "/" + folder.Items.Count + ")");
    
            foreach (Outlook.MailItem item in folder.Items)
              {
              Console.WriteLine(item.Subject + " (" + item.UnRead + ")");
              }
            }
          }
    
        static void Main(string[] args)
          {
          DisplayExchangeAccounts();
          }
        }
      }
    
    

    Thanks in advance for any hint,

    Guillaume.

    Friday, August 26, 2011 2:46 PM

Answers

  • Outlook 2007 can only log into one Exchange mailbox per Outlook session. To log into a different mailbox you'd need to exit and restart Outlook.
     
    There are 2 main ways to access other mailbox data for Outlook 2007.
     
    The profile can be set up to automatically log into other mailboxes, which are then considered as delegate mailboxes. That allows access to the other mailboxes from the Stores collection, and allows access to any folder or items if the correct permissions are set up.
     
    The other main way is to create a Recipient object using the Exchange alias for the desired mailbox, and then use NameSpace.GetSharedDefaultFolder() to return a Folder object for that specific folder. That method works only for default folders in that recipient's mailbox, it does not work for user created folders in that mailbox.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Guillaume666" <=?utf-8?B?R3VpbGxhdW1lNjY2?=> wrote in message news:0bad1989-6be6-425b-a8ee-7ee70ac1b6c1...

    Hi,

    I'm trying to work with several exchange accounts through Outlook 2007 with C# for VS 2008.

    Saddly our administrator had disabled EWS which worked well...

    Do you know a way to work with them?

    I can see every Exchange accounts in Outlook but when I try to read them it only works for the main exchange user (and all unReadCount value are false).

    I use the following code :

    namespace Outlook2007
     {
     class Program
      {
      public static void DisplayExchangeAccounts()
       {
       Outlook.Application applicationOutllok2007 = new Microsoft.Office.Interop.Outlook.ApplicationClass();
       Outlook.NameSpace ns = applicationOutllok2007.GetNamespace("MAPI");
       Outlook.Folders folders = ns.Folders;
    
       foreach (Outlook.MAPIFolder folder in folders)
        {
        Console.WriteLine(folder.Name + " (" + folder.UnReadItemCount + "/" + folder.Items.Count + ")");
    
        foreach (Outlook.MailItem item in folder.Items)
         {
         Console.WriteLine(item.Subject + " (" + item.UnRead + ")");
         }
        }
       }
    
      static void Main(string[] args)
       {
       DisplayExchangeAccounts();
       }
      }
     }
    
    

    Thanks in advance for any hint,

    Guillaume.


    Ken Slovak MVP - Outlook
    • Marked as answer by Guillaume666 Monday, August 29, 2011 7:31 AM
    Friday, August 26, 2011 2:59 PM

All replies

  • Outlook 2007 can only log into one Exchange mailbox per Outlook session. To log into a different mailbox you'd need to exit and restart Outlook.
     
    There are 2 main ways to access other mailbox data for Outlook 2007.
     
    The profile can be set up to automatically log into other mailboxes, which are then considered as delegate mailboxes. That allows access to the other mailboxes from the Stores collection, and allows access to any folder or items if the correct permissions are set up.
     
    The other main way is to create a Recipient object using the Exchange alias for the desired mailbox, and then use NameSpace.GetSharedDefaultFolder() to return a Folder object for that specific folder. That method works only for default folders in that recipient's mailbox, it does not work for user created folders in that mailbox.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Guillaume666" <=?utf-8?B?R3VpbGxhdW1lNjY2?=> wrote in message news:0bad1989-6be6-425b-a8ee-7ee70ac1b6c1...

    Hi,

    I'm trying to work with several exchange accounts through Outlook 2007 with C# for VS 2008.

    Saddly our administrator had disabled EWS which worked well...

    Do you know a way to work with them?

    I can see every Exchange accounts in Outlook but when I try to read them it only works for the main exchange user (and all unReadCount value are false).

    I use the following code :

    namespace Outlook2007
     {
     class Program
      {
      public static void DisplayExchangeAccounts()
       {
       Outlook.Application applicationOutllok2007 = new Microsoft.Office.Interop.Outlook.ApplicationClass();
       Outlook.NameSpace ns = applicationOutllok2007.GetNamespace("MAPI");
       Outlook.Folders folders = ns.Folders;
    
       foreach (Outlook.MAPIFolder folder in folders)
        {
        Console.WriteLine(folder.Name + " (" + folder.UnReadItemCount + "/" + folder.Items.Count + ")");
    
        foreach (Outlook.MailItem item in folder.Items)
         {
         Console.WriteLine(item.Subject + " (" + item.UnRead + ")");
         }
        }
       }
    
      static void Main(string[] args)
       {
       DisplayExchangeAccounts();
       }
      }
     }
    
    

    Thanks in advance for any hint,

    Guillaume.


    Ken Slovak MVP - Outlook
    • Marked as answer by Guillaume666 Monday, August 29, 2011 7:31 AM
    Friday, August 26, 2011 2:59 PM
  • Thank you for your reply.

     

    I understand better how it should works...

     

    I'm going to see what I can do with the first method because I had used peronnal folder to deal with bad values in unread message...

    Monday, August 29, 2011 7:30 AM