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

推荐订阅源

F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Secure Thoughts
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
博客园 - 司徒正美
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
B
Blog
The GitHub Blog
The GitHub Blog
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
Martin Fowler
Martin Fowler
博客园 - 叶小钗
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
S
Securelist
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
T
Threat Research - Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
Cloudbric
Cloudbric
The Cloudflare Blog
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Hacker News: Front Page
腾讯CDC
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
Google Online Security Blog
Google Online Security Blog
T
The Blog of Author Tim Ferriss

博客园 - 假正经哥哥

自定义PlantUML和C4 Model样式 - 假正经哥哥 - 博客园 [dotnet core]使用Peach简化Socket网络通讯协议开发 发布xxl-job executor dotnet core 执行器的实现 Service Discovery And Health Checks In ASP.NET Core With Consul [译]Serilog Tutorial 使用DotNetty编写跨平台网络通信程序 基于DotNet Core的RPC框架(一) DotBPE.RPC快速开始 - 假正经哥哥 使用CSharp编写Google Protobuf插件 使用VsCode编写和调试.NET Core项目 C#使用ICSharpCode.SharpZipLib.dll压缩文件夹和文件 xEasyApp之后端的介绍 如果利用xjplugin编写基于web的应用系统 Xgcalendar 新增Php demo jquery xgcalendar ,tree,contextmenu,tabpanel 插件遭遇盗版 基于jQuery打造TabPanel 安装Office2010后Vs2008打开网页文件假死的问题 Python 学习笔记(半ZZ半自己写) Python 学习记录(2) 杯具的GQL Python 学习记录(1)对象命名导致的问题
Exchange 2007 自定义传输规则
假正经哥哥 · 2011-04-17 · via 博客园 - 假正经哥哥

需求:公司域名从aep.com 修改为casoo.com 原域名仍可接收邮件,但是希望发到原域名的邮件 自动回复发送者告知:邮件域名已变更

原有的传输规则无法实现上述功能,那就只有自定义了。

首先copy 两个dll到开发服务器上

Microsoft.Exchange.Data.Transport.dll ,Microsoft.Exchange.Data.Common.dll (C:\Program Files\Microsoft\Exchange Server\Public directory) 

你可以编写两种传输规则:SmtpReceiveAgent,RoutingAgent

这里使用 后者 开始编码了,新建一个类库项目

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Routing;
using System.Diagnostics;

namespace AutoReplayForCustomerDomainRule
{
    public sealed class AutoReplayForCustomerDomainRoutingAgentFactory : RoutingAgentFactory
    {
        public override RoutingAgent CreateAgent(SmtpServer server)
        {
            return new AutoReplayForCustomerDomainRoutingAgent();
        }
    }

    public class AutoReplayForCustomerDomainRoutingAgent : RoutingAgent
    {
        public AutoReplayForCustomerDomainRoutingAgent()
        {
            base.OnSubmittedMessage += new SubmittedMessageEventHandler(AutoReplayForCustomerDomainRoutingAgent_OnSubmittedMessage);
            //base.OnResolvedMessage += new ResolvedMessageEventHandler(AutoReplayForCustomerDomainRoutingAgent_OnResolvedMessage);
        }

        void AutoReplayForCustomerDomainRoutingAgent_OnSubmittedMessage(SubmittedMessageEventSource source, QueuedMessageEventArgs e)
        {
            if (e.MailItem.FromAddress.IsValid)
            {
                string rpdomain = string.Format("{0}@{1}", e.MailItem.FromAddress.LocalPart, e.MailItem.FromAddress.DomainPart);
                bool isNeedReply = false;
                //e.MailItem.Message.Subject += rpdomain;
                //e.MailItem.Message.Subject += "|" + AppConfig.AutoReplyDomain;
                foreach (EnvelopeRecipient ep in e.MailItem.Recipients)
                {
                    if (ep.Address.IsValid && ep.Address.DomainPart.ToLower() ==AppConfig.AutoReplyDomain)
                    {
                        isNeedReply = true;
                        break;
                    }
                }

                if (isNeedReply)
                { 
                    //                  
                    EWSService.Create().SendMail(AppConfig.AutoReplySubject, AppConfig.AutoReplyMessage, new string[] { rpdomain });
                }
                
            }
        }             
      
    }
}

部署:

打开Exchange命令行

执行下面的命令:

net stop msexchangetransport # to stop the exchange transport service

install-transportagent -name "autoreply_v1" -assemblypath c:\Transrule\AutoReplayForCustomerDomainRule.dll -transportagentfactory AutoReplayForCustomerDomainRule.AutoReplayForCustomerDomainRoutingAgentFactory
enable-transportagent -identity "autoreply_v1"

get-transportagent -identity "autoreply_v1"

net start msexchangetransport