惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - DiryBoy

修复运行 tasklist 命令时提示 ERROR: Not found 删除坏掉的 Active Directory Domain 为 WSUS 服务器定期运行清理向导 Windows 10 下安装 npm 后全局 node_modules 和 npm-cache 文件夹的设置 在 Win10 命令行使用 Consolas + 微软雅黑 Setting up SSL for SCM-Manager with Microsoft CA and TortoiseHg Installing SCM-Manager Win 7 装 SQL Server 2008 后使用 Asp.Net 需要进行的一些配置 为 IE8 写一个转跳加速器 WPF 实现已绑定集合项目的移除时动画过渡 成功在 Win 7 下用 VirtualBox 装 Win 7,分享一些经验 如何写递归的 Lambda 表达式 使用动态生成的委托提高调用动态程序集的性能 在 Azure 中部署支持 MVC 的 Asp.Net 应用程序 DIY 自己的多点触摸系统 未来就在眼前 用 C# 实现的前缀树 - Trie 自己改造 VSPaste 插件 用C# 写的龙贝格(Romberg)积分法
为 Exchange 服务器编写自定义的反垃圾插件
DiryBoy · 2016-09-07 · via 博客园 - DiryBoy

Exchange 2010 的 Edge Transport 包含了一些 Anti-spam 的 Feature,如图:

image

都开启了,但是呢,还是会有漏网之鱼,而且把这些邮件自己列为 Junk 也起不了多大作用,这些 Feature 的设置也很鸡肋,没办法设置复杂一点的规则。于是我怒了,着手自己把这些漏网之鱼挡掉。

首先,是要找到相关的文档以及 SDK。文档入口在这里,然而里面提到的 Transport Agents SDK 的安装程序很坑,要你装个装不了的东西才给开始安装。后来发现其实可以不安装,直接从服务器上拷贝几个 DLL 和 XML 文件到本地,路径是 C:\Program Files\Microsoft\Exchange Server\V14\Public。接着用 Visual Studio 新建一个 .Net 3.5 的 Class Library,然后添加对这几个 DLL 的引用即可。

接下来的事情就是跟着文档的例子写(抄)一个 SmtpReceiveAgent 的架子了,然后看怎么处理 EndOfData。

Exchange 自带的 Content Filtering 会根据内容产生几个评分,其中一个叫 SCL(Spam Confidence Level),会存到邮件头里面,并以 X-MS-Exchange-Organization-SCL 命名。当这个评分超过 5 的时候,邮件就会被认为是垃圾邮件。

所以现在要做的就是自己扫描过邮件以后,把我的评分写到这个邮件头上面。邮件头可以通过以下方式拿到:

var message = e.MailItem.Message;
var headers = message.MimeDocument.RootPart.Headers;

然后通过 headers.FindFirst 方法找到 SCL 对应的记录,然后改变它,如果是空的就 new 一个 TextHeaderInsertAfterLastChild 即可。

写好后,要将编译好的 DLL 复制到服务器上安装,可以用 PowerShell 完成。安装的脚本是:

Install-TransportAgent -Name "MySpamFilterAgent" -TransportAgentFactory "CustomSpamFilterAgent.MySpamFilterAgentFactory" -AssemblyPath "C:\CustomSpamFilterAgents\CustomSpamFilterAgent.dll"
Set-TransportAgent MySpamFilterAgent -Priority 2
Enable-TransportAgent MySpamFilterAgent
Restart-Service MSExchangeTransport

卸载的脚本很简单,可以推出来。

如果想要 debug,那么要先 Attach 到 EdgeTransport.exe,然后在外面发封测试邮件到这服务器。

各种 Agent 的执行顺序可以在 PowerShell 用 Get-TransportPipeline | Format-List 打印出来。