【问题标题】:Programmatically moving items from Junk folder to Inbox in Outlook.Interop class?以编程方式将项目从垃圾文件夹移动到 Outlook.Interop 类中的收件箱?
【发布时间】:2014-11-28 03:32:30
【问题描述】:

我目前正在改进一个 MS Outlook 加载项,以提取最终在垃圾文件夹中带有“合法”地址的电子邮件,然后将它们移动到收件箱文件夹中。

这种情况在 Gmail 地址中经常发生,对于我们的工作人员来说有点麻烦,他们必须手动将这些电子邮件链接到他们的客户帐户。

有人尝试过吗?我已注册传入电子邮件事件处理程序以在收到电子邮件时读取垃圾文件夹,但我不断收到异常。我怀疑这与其中一些电子邮件是垃圾邮件有关。这仅仅意味着 MailItem 会有很多错误。

有人遇到过同样的问题吗?这是我的代码:

public void OutlookApplication_ItemReceived(string entryID)  
{
  //this.outlookNameSpace = this.application.GetNamespace("MAPI");
  //Outlook.MAPIFolder inbox = this.outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
  //Outlook.MAPIFolder junkFolder = this.outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderJunk);

  if (Properties.Settings.Default.AutoLink || Properties.Settings.Default.EnableLeadLoader)
  {
    Outlook.MailItem mail = null;
    try
    {
      this.Log("Email detected: incoming");
      mail = this.application.Session.GetItemFromID(entryID) as Outlook.MailItem;

      this.leadLoaderRecipient = Properties.Settings.Default.LeadLoaderRecipient.ToLower();

      Outlook.Recipients recips = mail.Recipients; //That's where its crashing as the object is null... if read from spam folder

      foreach (Outlook.Recipient recip in recips)
      {
        Outlook.PropertyAccessor pa = recip.PropertyAccessor;
        string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();

        if (Properties.Settings.Default.EnableLeadLoader)
        {
          if (smtpAddress.ToLower() == this.leadLoaderRecipient)
            this.ProcessLead(mail);
        }
      }
      if (Properties.Settings.Default.AutoLink)
      {
        this.AutoLink(mail, true);
      }
    }
    catch (Exception ex)
    {
      this.Log("Exception (ItemReceived): " + ex.ToString());
    }
    finally
    {
      if (mail != null)
      {
        Marshal.ReleaseComObject(mail);
      }
    }
  }
}

期待你们的想法! :) TIA!

【问题讨论】:

    标签: c# office-interop outlook-addin outlook-2010 mapi


    【解决方案1】:

    您的代码究竟何时运行?那是 Application.NewMailEx 事件处理程序吗?有什么例外?

    尝试在垃圾邮件文件夹上使用 Items.ItemAdd 事件,而不是使用 Application.NewMailEx。

    【讨论】:

    • 嗨@dmitry,这目前正在我实现的控制器中实现,它运行我的 OutlookApplication_ItemReceived 事件处理程序。我得到的例外是我的 MailItem 作为空对象返回。将电子邮件发送到收件箱时不会发生这种情况。
    • 您尝试过垃圾邮件文件夹上的 Items.ItemAdd 事件吗?
    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2018-06-08
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    相关资源
    最近更新 更多