Outlook Com Exception - c#

I have a c# .net app that opens an instance of outlook and populates the bcc section of the email. When I run .Net locally, it works fine. If I go to the server and open IIS and browse to the app, it works fine.
When I browse to the app in Internet Explorer, it won't open outlook and populate the bcc.
Here is my code to open the instance of outlook.
Outlook.Application outlookApplication = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApplication.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.BCC = emailList;
mailItem.Display(true);
Here is the warning from the event viewer in the server manager:
Exception information:
Exception type: COMException
Exception message: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
What am I missing or what do I need to do to get this to work?

Your code is running on the server, not the client. You need to use a client-side script for that - assuming your script has the right to actually create local COM objects and the user is using IE (no other browsers support COM obejcts).
Secondly, Outlook, just like any other Office app, cannot be used in a service (such as IIS).

Related

c# PowerPoint Slide interop and office dll registry error

I am in need of read a PPT/X PowerPoint File in C# code and display that in web form as image.
I did it using in VS 2013 C# .NET 4.0 and using dlls, Microsoft.office.interop.powerpoint.dll and Office.DLL.
It is working perfectly fine when running on local machine and working in local machine.
When I publish it on Azure Web Server or in Shared Server IIS,
I am ending up with
*
Error occurred: Retrieving the COM class factory for component with
CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the
following error: 80040154 Class not registered (Exception from
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
*
I copied both DLLs into BIN folder.
Still no use.
Any idea how can i resolve this!!
Thanks in advance.
Just try enabling the fusion logs, it may be the case that your library is not signed and due to that your are getting this exception. Try disabling the strong name validation using sn -Vr

Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005 Access is denied

I have an asp.net hosted in IIS. that uses the Com library "Microsoft Word 14.0 Object Library". I am using this to convert the word Document to HTML, on my machine it works. I have Office 2007 on my machine. but when i try to run my app on the server it gives me the Following error
Retrieving the COM class factory for component with CLSID
{000209FF-0000-0000-C000-000000000046} failed due to the following
error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005
E_ACCESSDENIED)).
i have given all the permissions to the aspnet user and other users full access but this does not work,
From the Start menu, click Run and type Dcomcnfg.exe.
In Component Services, click Console root, expand Component Services, expand Computers, expand My computer,expand DCOMConfig.
Search for Microsoft Word 14.0 Object Library. Click on it.
Right click and select Properties.
On security tab, select Customize in "Launch and Activation" section.
Click edit and add identity of app pool under which you application is running.
Repeat above step for "Access Permission"

Error while access local machine outlook emails from web application

I have made a C#.net application to access all my folders and emails from my local machine outlook.
To make this application I have used COM object, my application is working fine with my local machine using link localhost:51514/mymail/list
Sample code
Microsoft.Office.Interop.Outlook.Application app = null;
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon("abc#mydomain.com","password", true, true);
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
MapModel.InboxFolder = app.ActiveExplorer().Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
MapModel.CategoryList = SetCategoryList(MapModel.InboxFolder);
but when I put this application on server and then try to access my email I get error at runtime.
ERROR: Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005 Server execution failed (Exception from HRESULT:
0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
The requirement of my project : where ever I open my application, it should access all emails from Microsoft outlook on that machine and list emails in my application.
seeking for some help, Thanks in advance.

On button click outlook window doesn't open

I have a button on my asp.net page when I click on it it should open an outlook window but i get the following error.
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154.
I'm using in my c# page:
using Microsoft.Office.Interop.Outlook;// Version 12.0.0
In Web.Config:
<add assembly="Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
It gives an error at this line:
Updated code as per request, I am just trying to open new instance.
Application oApp = new Application();
_MailItem oMailItem = (_MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Just FYI, When I run it on my pc it's working ok, but on the live environment it gives me this error.
and if the problem with IIS how can I solve it
thanks in advance.
I think you want to open email client window on the client where the web browser is running and not on the server machine where IIS is running.
If so, you can simply use mailto links. It will open a outlook window if outlook is installed on the client machine.

Outlook 2007 from C# - COM exception, TYPE_E_LIBNOTREGISTERED

I'm trying to make a program that would open new Outlook 2007 message.
I've referenced from COM tab Microsoft Outlook 12.0 ObjectLibrary.
These items showed up in references in VS:
Microsoft.Office.Core
Microsoft.Office.Inerop.Outlook
Now I try to invoke following code:
var _outlookInstance = new Microsoft.Office.Interop.Outlook.Application();
var _message = (OutlookApp.MailItem)_outlookInstance.CreateItem(OutlookApp.OlItemType.olMailItem);
where OutlookApp==Microsoft.Office.Interop.Outlook namespace.
While invoking second line of listing I keep getting this exception: (InvalidCastException)
Unable to cast COM object of type
'Microsoft.Office.Interop.Outlook.ApplicationClass'
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 unregistered.
(Exception from HRESULT: 0x8002801D
(TYPE_E_LIBNOTREGISTERED)).
That code worked well for Outlook 2003 on my other station.
I'll be grateful for any ideas how to solve it.
This can also happen, when you have uninstalled an office 2013 installation and you return to office 2010.
There might be some registry keys and dlls left, which cause the office application to load the wrong dll(s).
Here is the fix: http://www.fieldstonsoftware.com/support/support_gsyncit_2013.shtml
Office is not properly installed on that machine. You can verify that with Regedit.exe, navigate to HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}\TypeLib to verify the type library GUID (should be {00062FFF-0000-0000-C000-000000000046}), then to HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046} to verify that the type library is indeed properly registered, using the correct type library version number. The latter part should be the problem.
If the target machine runs a 64-bit version of Windows, try setting the Project + Properties, Build, Platform Target to x86.
If you attempt to access Outlook from Visual Studio and get the error:
TF400424: Failed to send to Microsoft Outlook: Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' 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)).
Do the following:
Using the Registry, navigate to: HKEY_CLASSES_ROOT\TypeLib{00062FFF-0000-0000-C000-000000000046}
Delete the version keys (e.g. 9.5) for any version of Outlook that is not installed on your system based on the version table provided below. For example, if you are not using Outlook 2013 then remove the "9.5" entry. If you are not using Outlook 2010 then remove the the "9.4" entry. DO NOT DELETE the entry for the version that was configured in Step #1
Outlook 2007 ==> 9.3
Outlook 2010 ==> 9.4
Outlook 2013 ==> 9.5
Reference: https://support.netdocuments.com/hc/en-us/articles/205219170--Library-Not-Registered-error-when-using-EMS-in-Outlook
Had the same problem with the following code:
Dim OutlookMessage As Outlook.MailItem
Dim AppOutlook As New Outlook.Application
OutlookMessage = AppOutlook.CreateItem(Outlook.OlItemType.olMailItem)
Replacing the first line with the following solved it for me.
Dim OutlookMessage As Object
(sample in VB but same should apply to C#)

Categories

Resources