2016-05-18 42 views
-2

您好首先感谢我的英语我想在到达收件箱之前过滤电子邮件,例如,如果有人在组织内部发送电子邮件,我必须先检查电子邮件是否不是垃圾邮件,然后允许收件箱,如果电子邮件是垃圾邮件或简单的黑名单,然后直接删除 我曾尝试在收件箱之前过滤电子邮件

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; 
using System.Windows.Forms; 

namespace OutlookAddIn1 
{ 
    public partial class ThisAddIn 
    { 
     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 
      this.Application.NewMail += new Microsoft.Office.Interop. 
    Outlook.ApplicationEvents_11_NewMailEventHandler(
    ThisAddIn_NewMail); 


     } 
     private void ThisAddIn_NewMail() 
     { 
      Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application. 
       ActiveExplorer().Session.GetDefaultFolder 
       (Outlook.OlDefaultFolders.olFolderInbox); 
      Outlook.Items items = (Outlook.Items)inBox.Items; 
      Outlook.MailItem moveMail = null; 
      items.Restrict("[UnRead] = true"); 
      Outlook.MAPIFolder destFolder = inBox.Folders["Test"];//create a test folder first in your outlook box 
      foreach (object eMail in items) 
      { 
       try 
       { 
        moveMail = eMail as Outlook.MailItem; 
        if (moveMail != null) 
        { 
         string titleSubject = (string)moveMail.Subject; 
         if (titleSubject.IndexOf("Test") > 0) //send email to inbox subject test 
         { 
          moveMail.Move(destFolder); 
         } 
        } 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.Message); 
       } 
      } 
     } 
     private void ThisAddIn_Shutdown(object sender, System.EventArgs e) 
     { 
     } 

     #region VSTO generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InternalStartup() 
     { 
      this.Startup += new System.EventHandler(ThisAddIn_Startup); 
      this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
     } 

     #endregion 
    } 
} 

回答

0

不能做到这一点。收件箱文件夹上的Application.NewMail或Items.ItemAdd是您可以访问新邮件的最早时间。 Outlook将同时看到它。

+0

是他们的任何其他方法过滤邮件到达收件箱之前? – noob

+0

不可以,除非它是检索并创建新项目的代码。 –

相关问题