Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I have created windows service in .Net 4.5.Service is written to open outlook client, read emails from Inbox folder, downloads attachments.The code written is correct, since I have run & tested it in console application project. But when I install the web service using "installutil" and run it, the service throws following error on following line of code:

Outlook.Application myApp = new Outlook.Application();

Error:

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).

FYI, the service is not running on my machine,I feel that service might require some permission, if so please let me know how to assign permissions to windows service.


What I have tried:

Code here :-

Outlook.Application myApp = new Outlook.Application(); Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI"); ns = myApp.GetNamespace("MAPI");

Error :-
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
Posted
Updated 5-Apr-16 1:01am
Comments
Kornfeld Eliyahu Peter 5-Apr-16 6:56am    
It is possible that DCOM not enables on that machine...
Check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\OLE\EnableDCOM...
.net developer123456789 5-Apr-16 7:04am    
Value Data Set : Y
is it EnableDCOM ?
Kornfeld Eliyahu Peter 5-Apr-16 7:07am    
That seems all right...
Can you run your the console version to test?
What user runs the service?
.net developer123456789 5-Apr-16 7:11am    
Yes Working on console application..
Code here :-
Outlook.Application myApp = new Outlook.Application(); Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI"); ns = myApp.GetNamespace("MAPI");
I try Local service..
Kornfeld Eliyahu Peter 5-Apr-16 7:14am    
Change Local Service to some interactive usr (like the logged-in user) and test it...

1 solution

Is Outlook installed on the machine? For what it's worth, you're not going to get this working, Outlook is not suitable for automation from environments that have no interactive desktop. What happens if Outlook needs to show a dialogue box or prompt or error? Who is going to click "ok" when the alert can't be seen? Exactly whose account is Outlook going to use when your service will be running as system or something like that and not the interactive user?

If you need a service that does these things then automating Outlook is the wrong way to go, you should be emulating Outlook instead and using POP3\IMAP and SMTP to achieve the things you want, or use Exchange Web Services if you're using Exchange.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 5-Apr-16 7:06am    
The problem of UI can be solved by running the service with interactive user instead of one of the usual, build-in accounts...
F-ES Sitecore 5-Apr-16 7:15am    
And what if no-one is logged in at all? If you need someone to be logged in using a service is pointless, you might as well have it as a GUI-less background app and whack it in the start-up folder.
Kornfeld Eliyahu Peter 5-Apr-16 7:21am    
You can assign your rights to a service even you not logged-in...
F-ES Sitecore 5-Apr-16 7:36am    
And when Outlook pops up an alert? Who clears it?

Perusing this as a service is simply a ridiculous idea that is so fragile it isn't worth bothering about. The only reason it has been done as Outlook automation is because that was the easiest route for the OP to get the task done, but just cos it works from Console doesn't mean it'll work as service and just cos automating Outlook is easy that doesn't make it the right solution, especially if that automation is going to happen from a service\website etc.
.net developer123456789 5-Apr-16 7:30am    
Thanks for your help.. its working fine for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900