[英]Sending Email through Outlook not working on IIS
在调试中运行时,我的代码可以正常运行,并且可以通过Outlook适当地发送电子邮件,但是当我将其放在IIS(同一台计算机和开发人员)上时,电子邮件就不会通过。 有什么想法吗?
当前代码
try
{
//creates outlook app
Outlook.Application oApp;
//checks to see if outlook is already running, if not create a new instance of it
try {
oApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
}
catch (Exception ex) {
oApp = new Outlook.Application();
}
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "This is an email to notify you that there is a new Experimental MEO added";
//Subject line
oMsg.Subject = "NEW MEO EXPERIMENTAL ADDED.";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email@address.com");
oRecip.Resolve();
// Send.
((Outlook._MailItem)oMsg).Send();
// Clean up.
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oMsg);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecip);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecips);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp);
}//end of try block
catch (Exception ex)
{
}//end of catch
任何Office应用程序(包括Outlook)都不能在服务(例如IIS)中运行。 您可以选择以下选项:扩展MAPI(仅C ++或Delphi), 兑换 (包装扩展MAPI,可以从任何语言(包括C#)进行访问),EWS(仅Exchange)或直接SMTP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.