仅在Outlook Online(非缓存)模式下为COMException

问题描述 投票:0回答:1

下面显示的示例代码说明了我所遇到的问题,即当我以联机模式启动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);
    }
}

}

c# outlook vsto outlook-addin
1个回答
1
投票
您绝对不要触摸正在提交的消息-即使成功完成,用OOM触摸项目也会中止提交过程。请改用Application.ItemSend事件-这是您将项目移交给后台处理程序并发送之前的最后机会。
© www.soinside.com 2019 - 2024. All rights reserved.