C# 在收件箱之前过滤电子邮件
您好首先对不起我的英语我想在到达收件箱之前过滤电子邮件例如,如果有人在组织内部发送电子邮件,首先我必须检查电子邮件是否不是垃圾邮件,然后允许进入收件箱,如果电子邮件是垃圾邮件或简单的黑名单,然后直接删除 我试过了C# 在收件箱之前过滤电子邮件,c#,.net,email,outlook-addin,C#,.net,Email,Outlook Addin,您好首先对不起我的英语我想在到达收件箱之前过滤电子邮件例如,如果有人在组织内部发送电子邮件,首先我必须检查电子邮件是否不是垃圾邮件,然后允许进入收件箱,如果电子邮件是垃圾邮件或简单的黑名单,然后直接删除 我试过了 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Outlook = Microsoft.Office.I
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
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml.Linq;
使用Outlook=Microsoft.Office.Interop.Outlook;
使用Office=Microsoft.Office.Core;
使用System.Windows.Forms;
命名空间了望AddIn1
{
公共部分类ThisAddIn
{
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
this.Application.NewMail+=新的Microsoft.Office.Interop。
Outlook.ApplicationEvents\u 11\u NewMailEventHandler(
本附件(新邮件);
}
私有无效此addin_NewMail()
{
Outlook.MAPIFolder收件箱=(Outlook.MAPIFolder)此应用程序。
ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items=(Outlook.Items)inBox.Items;
Outlook.MailItem moveMail=null;
items.Restrict(“[未读]=true”);
Outlook.MAPIFolder destFolder=收件箱。文件夹[“测试”];//首先在Outlook框中创建一个测试文件夹
foreach(邮件中的对象)
{
尝试
{
moveMail=以Outlook.MailItem的形式发送电子邮件;
if(moveMail!=null)
{
string titleSubject=(string)moveMail.Subject;
if(titleSubject.IndexOf(“Test”)>0)//发送电子邮件到收件箱主题测试
{
moveMail.Move(destFolder);
}
}
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
#区域VSTO生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
#端区
}
}
不能这样做。收件箱文件夹中的Application.NewMail或Items.ItemAdd是您最早可以访问新邮件的时间。Outlook将同时看到它 他们是否有任何其他方法在电子邮件到达收件箱之前过滤电子邮件?没有。除非是您的代码检索并创建新邮件。