none
Application.Session.Accounts does not contain an entry for newly created accounts during the session. RRS feed

  • Question

  • My Outlook 2010 add-in enumerates over Application.Session.Accounts to get a list of accounts available.

    However, it seems like it only contains the accounts that currently exist during start-up. If a new account is added, Application.Session.Accounts will not have the new account until Outlook is restarted.

    Is there any way to get the newly added accounts, without having to restart Outlook?

    Thanks!


    Friday, December 6, 2013 4:15 AM

Answers

  • I can reproduce this problem... It looks like Outlook caches the accounts on startup.

    I am not aware of a way to access IOlkAccountManager directly in .Net. You might want to look at the RDOSession.Accounts collection in Redemption (it can be used from .Net) - it wraps IOlkAccountManager and does not cache any data.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, December 6, 2013 4:24 PM

All replies

  • Do you use the same behavior for the IOlkAccountManager interface (Namespace.Accounts wraps it)?

    You can see IOlkAccountManager in OutlookSpy (click IOlkAccountManager  button).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, December 6, 2013 4:42 AM
  • IOlkAccountManager with OutlookSpy displays the correct behavior...which is strange if Namespace.Accounts wraps it.  I'm using the 2010 COM Interop, getting the Namespace.Accounts.Count and iterating with the indexer. Perhaps I should try calling Namespace.Accounts.GetEnumerator() and see if I get a different result?

    Btw, thanks for Outlook Spy. It makes debugging so much faster by enabling quick access to the outlook object model.


    Friday, December 6, 2013 5:02 AM
  • What do you see if you click Namespace, select Accounts, click Browse, go to the EnumVariant tab? Is the new account there?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, December 6, 2013 5:42 AM
  • Hello Jonathan,

    I would recommend breaking the following line of code into separate lines:

    Application.Session.Accounts 

    For example:

    Dim ns as Outlook.Namespace
    Dim accs as Outlook.Accounts
    Set ns = Application.Session 
    Set accs = ns.Accounts 
    
    Finally, please make sure that you installed updates and service packs for Outlook/Office (SP2).
    Friday, December 6, 2013 11:56 AM
  • No, the new account is not in Namespace,Accounts, Browser, EnumVariant with OutlookSpy. However, the new account is listed in IOlkAccountManager. So, MS must not be wrapping it properly. Is there a managed way to get access to IOlkAccountManager?

    Friday, December 6, 2013 4:15 PM
  • I can reproduce this problem... It looks like Outlook caches the accounts on startup.

    I am not aware of a way to access IOlkAccountManager directly in .Net. You might want to look at the RDOSession.Accounts collection in Redemption (it can be used from .Net) - it wraps IOlkAccountManager and does not cache any data.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, December 6, 2013 4:24 PM
  • Thanks for the help and verifying I'm not losing my mind. OOM hoses me yet again :)
    Friday, December 6, 2013 4:38 PM