I'm working on a Selenium test which generates a report and then sends the report to an email address when it's finished. The script works flawlessly up until I have to send the email report.
The weird thing is that if I run the script from inside Visual Studio, the email sends fine, but when I build the solution and then set the script to run automatically from the task schedule it fails. The rest of the script runs fine, the report gets generated, it just doesnt send the email.
I'm not a Visual Studio expert, so I'm thinking it may possibly be something in my settings.
Here's the code to send the email using Outlook:
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "Please find the attached Contract Remaining Hours report for the week of " + DateTime.Today.ToString("D");
String sDisplayName = fileName;
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMsg.Attachments.Add
(pathToFile + fileName, iAttachType, iPosition, sDisplayName);
oMsg.Subject = "Contract Remaining Hours Report " + DateTime.Today.ToString("D");
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("tom.depiera@tbs.toshiba.com");
oRecip.Resolve();
oMsg.Send();