【发布时间】:2019-01-14 05:38:02
【问题描述】:
我使用 Asp.net WebForm 我的 Outlook 应用程序有问题。当用户想在 Outlook 中通过电子邮件从浏览器提交报告/订单时,它会创建 2 封电子邮件而不是 1 封。我真的不明白可能是什么问题。
这里是负责创建和发送邮件的部分:
//Send email
try
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
MailAddress to = new MailAddress(email_primary);
MailAddress cc = new MailAddress(email_cc);
mailItem.To = to.ToString();
mailItem.CC = cc.ToString();
mailItem.Subject = "MB Accessories Order";
mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mailItem.Body = "Dear Colleagues, Please find below my MB Accessories & Collection enquiry for MBCME price (VAT included) and availability. FullName:" + Fullname_converted + " Items:" + joinedData + "";
mailItem.Display(false);
//mailItem.Send();
Response.Write("E-mail sent!");
}
catch (Exception eX)
{
throw new Exception("cDocument: Error occurred trying to Create an Outlook Email" + Environment.NewLine + eX.Message);
}
如果您需要更多信息,请告诉我。
【问题讨论】:
-
双击触发功能两次?你调试了吗?被击中两次了吗?
-
一般来说,尝试从 Web 应用程序自动化 Office 应用程序不受支持,并且往往会产生各种不错的副作用。这很可能就是其中之一。
-
要从 ASP.Net WebForms 应用程序发送电子邮件,要么采用手动路由并使用 SmtpClient(或更现代的东西)构建它,要么通过 SendGrid 等外部服务发送它。
-
@Paul-Jan 我想使用 Smtp,但我不使用它,因为我们仅在 Intranet 中使用此 Web 应用程序。 :)
标签: c# asp.net email webforms outlook