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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News | PayPal Newsroom
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
K
Kaspersky official blog
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Last Watchdog
The Last Watchdog
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Security Archives - TechRepublic
Security Archives - TechRepublic
V
V2EX
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
F
Full Disclosure
I
Intezer
Schneier on Security
Schneier on Security
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 聂微东
M
MIT News - Artificial intelligence
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
量子位
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
Google Online Security Blog
Google Online Security Blog
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
C
Check Point Blog
N
Netflix TechBlog - Medium
博客园 - Franky
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
S
Securelist

博客园 - 假正经哥哥

自定义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