仅限 Outlook Online(非缓存)模式中的 COMException
COMException in Outlook Online (non-cached) Mode only
下面显示的示例代码说明了我遇到的问题,即当我在联机模式下启动 Outlook 时,我无法获得传递给 OutboxItems_ItemAdd 处理程序的邮件项目的大部分属性。返回的错误是:
Attachments = {System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004010F
--- End of inner exception stack trace ---
at System.Runtime...
尝试在 SentItems_ItemAdd 处理程序中检索邮件项的属性时,我没有收到此错误。另外,重要的是要注意,在 Outlook 缓存模式下一切正常;发件箱处理程序中的问题仅在 Outlook 以联机模式启动时出现。这是一个错误,还是我做错了什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace OnlineErrorTest{
public partial class ThisAddIn{
Outlook.Folder sentFolder;
Outlook.Folder outboxFolder;
Outlook.Items sentItems;
Outlook.Items outboxItems;
private void ThisAddIn_Startup(object sender, System.EventArgs e) {
sentFolder = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
outboxFolder = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) as Outlook.Folder;
sentItems = sentFolder.Items;
outboxItems = outboxFolder.Items;
sentItems.ItemAdd += SentItems_ItemAdd;
outboxItems.ItemAdd += OutboxItems_ItemAdd;
}
private void OutboxItems_ItemAdd(object Item) {
Outlook.MailItem mi = Item as Outlook.MailItem;
Outlook.Recipients r = mi.Recipients; //CAUSES EXCEPTION //System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004010F
}
private void SentItems_ItemAdd(object Item) {
Outlook.MailItem mi = Item as Outlook.MailItem;
Outlook.Recipients r = mi.Recipients; //WORKS FINE
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) {
}
private void InternalStartup(){
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
}
}
错误代码是 MAPI_E_NOT_FOUND
,这意味着该项目不再存在 - 这不足为奇:当您的代码到达它时,Exchange Server 很可能已经发送了邮件并将其移动到已发送邮件文件夹。
您永远不应该触摸正在提交的消息 - 即使您成功地这样做了,触摸带有 OOM 的项目也会中止提交过程。请改用 Application.ItemSend
事件 - 这是您在将项目移交给后台处理程序并发送之前访问该项目的最后机会。
下面显示的示例代码说明了我遇到的问题,即当我在联机模式下启动 Outlook 时,我无法获得传递给 OutboxItems_ItemAdd 处理程序的邮件项目的大部分属性。返回的错误是:
Attachments = {System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004010F
--- End of inner exception stack trace ---
at System.Runtime...
尝试在 SentItems_ItemAdd 处理程序中检索邮件项的属性时,我没有收到此错误。另外,重要的是要注意,在 Outlook 缓存模式下一切正常;发件箱处理程序中的问题仅在 Outlook 以联机模式启动时出现。这是一个错误,还是我做错了什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace OnlineErrorTest{
public partial class ThisAddIn{
Outlook.Folder sentFolder;
Outlook.Folder outboxFolder;
Outlook.Items sentItems;
Outlook.Items outboxItems;
private void ThisAddIn_Startup(object sender, System.EventArgs e) {
sentFolder = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
outboxFolder = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) as Outlook.Folder;
sentItems = sentFolder.Items;
outboxItems = outboxFolder.Items;
sentItems.ItemAdd += SentItems_ItemAdd;
outboxItems.ItemAdd += OutboxItems_ItemAdd;
}
private void OutboxItems_ItemAdd(object Item) {
Outlook.MailItem mi = Item as Outlook.MailItem;
Outlook.Recipients r = mi.Recipients; //CAUSES EXCEPTION //System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004010F
}
private void SentItems_ItemAdd(object Item) {
Outlook.MailItem mi = Item as Outlook.MailItem;
Outlook.Recipients r = mi.Recipients; //WORKS FINE
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) {
}
private void InternalStartup(){
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
}
}
错误代码是 MAPI_E_NOT_FOUND
,这意味着该项目不再存在 - 这不足为奇:当您的代码到达它时,Exchange Server 很可能已经发送了邮件并将其移动到已发送邮件文件夹。
您永远不应该触摸正在提交的消息 - 即使您成功地这样做了,触摸带有 OOM 的项目也会中止提交过程。请改用 Application.ItemSend
事件 - 这是您在将项目移交给后台处理程序并发送之前访问该项目的最后机会。