C# - error while sending email from outlook

1

I have a C# exe which sends email from Outlook, it works fine if run manually.

I am trying to run it through Task scheduler but it gives following error:

System.Runtime.InteropServices.COMException (0x80080005): 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)).
at sendMail.Program.Main(String[] args) in D:\Recovered\Root\Projects\sendMail\sendMail\Program.cs:line 20
c#
email
outlook
scheduled-tasks

3 Answers

1

I have found a hack. I could fix the exception but it was sending emails as Microsoft does not allow COM objects to operate through a service (in my case Task Scheduler).

I created a script and triggered command from it every few hours as needed, since it was running as a program and not a service, it works fine, the only disadvantage being sleep calls invoked from my script.

answered on Stack Overflow Dec 19, 2017 by Devharsh Trivedi
0

Microsoft's manual provides this:

Cause: If many COM+ applications run under different user accounts that are specified in the This User property, the computer cannot allocate memory to create a new desktop heap for the new user. Therefore, the process cannot start.

WORKAROUND: To work around this problem, modify the value of the following registry subkey: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

answered on Stack Overflow Dec 17, 2017 by Barr J
0

Outlook is a singleton - COM system will refuse to marshal calls between two processes running in different security contexts.


User contributions licensed under CC BY-SA 3.0