Is it possible to use Automation for Outlook 2003 with Silverlight 4? Or maybe there are some different way to use Outlook 2003 MAPI in Silverlight application?
I’m using Silverlight 4 and I’m trying interact with Outlook in this way:
dynamic outlook = AutomationFactory.GetObject("Outlook.Application");
For Outlook 2007/2010 all works fine.
But when I try use any field of dynamic instance (for example outlook.Session) from Outlook 2003 then I’ve get NotSupportedException. It’s only Outlook 2003 problem.
I found article http://msdn.microsoft.com/en-us/library/aa159619%28office.11%29.aspx but it’s useless for Silverlight application (impossible to get reference to office assembly or COM directly).
Type.GetTypeFromProgID is useless too, Silverlight doesn’t support it.
I’ve finally found an answer.
Most of actions can be performed using standard Outlook 2003 object model. All these actions described in this Microsoft article.
Main difference between examples in article and Silverlight code – we can’t refer Interop Outlook assembly, so we need to use dynamics.
So it’s pretty easy to get all contacts from contact list or all inbox emails (see article). Most difficult part is obtaining list of created user’s accounts. Outlook 2003 object model provide possibility to obtain only one (default) account:
But it’s still doesn’t suitable for me. It’s very sad, but there is no Session.Accounts property in Outlook 2003 object model. So I’ve found only one tricky way to obtain list of accounts.
Main trick is in use of AutomationFactory.CreateObject(“WScript.Shell”). Now it’s possible to get account information directly from registry using RegRead method. By the way this code works well even for Outlook 2007/2010. And as for me it’s most preferable way if accounts should be collected silently (there is no need to launch Outlook before data collecting).