Reputation: 711
I have built a small application which periodically sends emails to different recipients.
Code is pretty simple using C#:
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
...
OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.To = "[email protected]";
mailItem.Subject = "Random subject";
mailItem.Body = "Random body";
mailItem.Send();
When I run .exe located on my machine it successfully sends an email, but when it's being run from task scheduler it hits some errors.
This is a result of task scheduler running this exe
Also, it's not hitting some exceptions from the task scheduler, it seems just to be timing out, I guess waiting for Outlook for some permissions.
Also Outlook programmatic access is set to:
====================================
Edit1: Program is timing out @ OutlookApp outlookApp = new OutlookApp();
Upvotes: 1
Views: 199
Reputation: 546
Make sure that the task scheduler task is configured to run using the proper computer/network/domain account (e.g. the credentials you typed in when you ran the app on your machine). The local system account (windows default) falls outside this category.
Upvotes: 1