我使用非常簡單的代碼在我的c#應用程序中使用outlook生成電子郵件。當Outlook已經打開時它工作正常(即使它要求打開電子郵件的權限。但是在我授予訪問權限後,打開一個新的Outlook郵件窗口並顯示生成的電子郵件)。但真正的問題是,如果Outlook沒有在該行Outlook郵件應用程序c#
Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email);
ERROR:An exception (first chance) of type 'System.Runtime.InteropServices.COMException' occurred in Birthday_Mailing.dll.
Additional information: discontinued operation (Exception from HRESULT: 0x80004004 (E_ABORT))
If a handler is available for this exception, the program may continue to run safely.
打開應用程序崩潰和我的整個代碼可以看出如下
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;
我不是在編碼專家。有人能幫我找到實際問題在哪裏嗎?提前致謝!
是不是收件人某種列表或數組?你不應該有一些索引或鍵? – Gnqz
@Gnqz我有索引,但它也給出了同樣的錯誤。當應用程序打開時,它工作得很好。所以我不認爲這是真正的問題。我猜想權限有問題 – Isuru
服務器使用什麼類型的數據庫?你看到這篇文章了嗎? https://social.technet.microsoft.com/Forums/sharepoint/en-US/b3ba89ca-48f9-47dd-92e2-c77d8585ac94/operation-aborted-exception-from-hresult-0x80004004-eabort – Gnqz