0

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();
Tom D
  • 351
  • 1
  • 4
  • 13
  • Do you pass the attachments using an absolute path? You could add some logs to determine the cause of the issue. – user7217806 Dec 25 '19 at 17:10
  • I'm getting the following error after adding logging `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)). ` – Tom D Dec 25 '19 at 17:31
  • Is the task executed as another user as Visual Studio? See this [question](https://stackoverflow.com/questions/12861072/why-am-i-receiving-exception-from-offices-outlook-library). – user7217806 Dec 26 '19 at 08:19
  • 1
    Im trying to run the script after Visual Studio has exited. I ended up just using System.Net.mail to do what I needed – Tom D Dec 26 '19 at 21:59

0 Answers0