outlook中的NewmailEx事件无法获取未读邮件

Unread mail can't be get in NewmailEx event in outlook

我在下面附上我的代码

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    this.Application.NewMail += new Microsoft.Office.Interop.Outlook
       .ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}
private void ThisApplication_NewMail()
{
    Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
        .Session.GetDefaultFolder(Outlook
        .OlDefaultFolders.olFolderInbox);
    Outlook.Items inBoxItems = inBox.Items;
    Outlook.MailItem newEmail = null;
    inBoxItems = inBoxItems.Restrict("[Unread] = true");

    foreach (object collectionItem in inBoxItems)
    {
        newEmail = collectionItem as Outlook.MailItem;
        if (newEmail != null)
        {
            if (newEmail.Attachments.Count > 0)
            {
                for (int i = 1; i <= newEmail
                   .Attachments.Count; i++)
                {
                    newEmail.Attachments[1].Delete();

                }
            }
        }
    }
}

请帮我阅读第一封邮件.....当 outlook 打开时...

你好像用的是 NewMail event, but not the NewMailEx 那个。

NewMailEx 事件在新邮件到达收件箱时且在客户端规则处理发生之前触发。您可以使用 EntryIDCollection 数组中返回的条目 ID 来调用 NameSpace.GetItemFromID 方法并处理该项目。请谨慎使用此方法,以尽量减少对 Outlook 性能的影响。但是,根据客户端计算机上的设置,在新邮件到达收件箱后,垃圾邮件过滤和将新邮件从收件箱移动到另一个文件夹的客户端规则等过程可能会异步发生。您不应该假设在这些事件触发后,收件箱中的项目数量总是会增加一个项目。

您可能还会发现以下系列文章有帮助: