【发布时间】:2016-02-19 00:16:34
【问题描述】:
我使用一个非常简单的代码在我的 c# 应用程序中使用 Outlook 生成电子邮件。当 Outlook 已打开时,它工作正常。(即使它要求打开电子邮件的权限。但在我授予访问权限后,将打开一个新的 Outlook 消息窗口,其中包含生成的电子邮件)。但真正的问题是,如果未打开 Outlook,应用程序会在该行崩溃
Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email);
错误:Birthday_Mailing.dll 中出现“System.Runtime.InteropServices.COMException”类型的异常(第一次机会)。
附加信息:停止操作(HRESULT 异常:0x80004004 (E_ABORT))
如果有可用于此异常的处理程序,则程序可以继续安全运行。
我的整个代码如下所示
public void SendMail(string email, string name)
{
//// Create the Outlook application by using inline initialization.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
////Create the new message by using the simplest approach.
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email); //oRecips.Add(t);
oTORecipt.Type = (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olTo;
oTORecipt.Resolve();
oMsg.Subject = "Herzlichen Glückwunsch";
oMsg.HTMLBody = "<html>" +
"<head>" +
"<title>Happy Birthday</title>" +
"</head>" +
"<body style='background-color:#E6E6E6;'>" +SelectImage+
"<div style='font-family: Georgia, Arial; font-size:14px; '>Liebe/r " + " " +
name + ",<br /><br />" +
"alles Gute zum <b>Geburtstag!</b> Wir wünschen einen schönen Tag und für das kommende Jahr Gesundheit, Glück und Erfolg." +
"<br /><br /><br /><br /><br />" +
"Mit den besten Grüßen,<br />" +
"XXYYZZ" +
"</div>" +
"</body>" +
"</html>";
oMsg.Save();
oMsg.Display();
oMsg = null;
oApp = null;
我不是编码专家。有人可以帮我找到实际问题在哪里吗?提前致谢!
【问题讨论】:
-
Recipients 不是某种列表或数组吗?你不应该有一些索引或键吗?
-
@Gnqz 我有索引,但当时它也给出了同样的错误。打开应用程序时它工作得很好。所以我认为这不是真正的问题。我猜是权限有问题
-
您的服务器使用什么类型的数据库?你看到这篇文章了吗? social.technet.microsoft.com/Forums/sharepoint/en-US/…
-
@Gnqz SQL server 2008。我要去看看那篇文章
-
@MikeMiller 它工作得还不错。但是在将其作为答案发布之前必须进行更多测试。非常感谢!!!