ldragicevic
ldragicevic

Reputation: 711

Aapplication using Outlook failing to send emails - when started from Windows Task Scheduler

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 enter image description here

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:

enter image description here

====================================

Edit1: Program is timing out @ OutlookApp outlookApp = new OutlookApp();

Upvotes: 1

Views: 199

Answers (1)

Goose
Goose

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

Related Questions