After searching on the web without success, here's my question.
I've a task that i want to schedule to retrieve the attachment of an email from outlook and extract the data. It works fine when I launch the task manually but whenever I try to launch it through a scheduled task it fails with the error :
COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
It occurs when the program tries to retrieve or create an instance of Outlook as follow:
private Application GetApplicationObject()
{
Application application = null;
if (Process.GetProcessesByName("OUTLOOK").Any())
{
application = Marshal.GetActiveObject("Outlook.Application") as Application;
}
else
{
application = new Application();
}
return application;
}
I tried several ways (batch file, .exe file, parameter from a program) but they all failed. It was launched with the same account that was use to launch the task manually.
Can someone help me ? Any help would be appreciated! Cheers!
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
You may consider using a low-level API (or any other third-party wrappers) - Extended MAPI on which Outlook is based on. Or EWS in case of Exchange profiles, see EWS Managed API, EWS, and web services in Exchange for more information.
Just a couple of thoughts:
It could be a GUI issue. According to this answer, GUI tasks cannot be run from scheduled tasks. There may be a workaround, but I am not aware of one.
It could be a context or permission issue. What settings are you configuring in the task, and are they the same as when you run the task outside of task scheduler?
User contributions licensed under CC BY-SA 3.0