Trying to automatically generate a mail message via Outlook -
Added a reference to Microsoft.Office.Interop.Outlook 14.0.0.0
It works on a Win 8/Office 2013 PC, but fails with the following exception on Win 7/Office 2010.
Code:
Application outlookApp = new Application();
MailItem message = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
message.Subject = "subject";
message.Display(message);
message.HTMLBody = "body" + message.HTMLBody; //to get default signature
The exception is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
Solution ended up being:
http://www.fieldstonsoftware.com/support/support_gsyncit_2013.shtml
Lync 2013 was installed on top of Office 2010. This adds a registry entry to HKCR\TypeLib{00062FFF-0000-0000-C000-000000000046}.
Subkey to that registry entry will be different numbered folders, indicating version numbers of Office installed. (9.4 in this case, indicates 2010, 9.5 indicates 2013). Once the version number not consistent with the version of Outlook was deleted, it was resolved.
User contributions licensed under CC BY-SA 3.0