我正在进行硒测试,该测试会生成报告,然后在完成后将报告发送到电子邮件地址。该脚本可以完美运行,直到我必须发送电子邮件报告为止。
奇怪的是,如果我从Visual Studio内部运行脚本,则电子邮件会正常发送,但是当我构建解决方案然后将脚本设置为从任务计划中自动运行时,它将失败。脚本的其余部分运行良好,生成了报告,只是不发送电子邮件。
我不是Visual Studio专家,所以我认为这可能是我的设置中的问题。
以下是使用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();