【问题标题】:Unread mail can't be get in NewmailEx event in outlookOutlook的NewmailEx事件中无法获取未读邮件
【发布时间】:2015-05-08 00:38:11
【问题描述】:
  • 我想在收到新邮件时删除附件.....
  • 所以我使用 NewmailEx 事件.....也尝试了 Newmail 事件.....
  • 我打开 Outlook --> 向我的 Outlook 邮件发送邮件 --> 事件被触发 --> 但收到的邮件未显示在我的未读邮件中,即 c# 编码没有收到收到的邮件 (这只发生在第一封邮件..关闭和打开 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 打开时...

【问题讨论】:

    标签: c# outlook


    【解决方案1】:

    您似乎使用了NewMail 事件,但没有使用NewMailEx 事件。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      相关资源
      最近更新 更多