吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3691|回复: 5
收起左侧

[其他转载] C# 获取Exchange 2013 发送的邮件附件并保存(截取邮箱内容)

[复制链接]
MartinLee 发表于 2019-5-10 17:25
本帖最后由 MartinLee 于 2019-6-24 17:59 编辑

需求是在一台Windows server 2012的服务器上获取Exchange 2013收件人信息及附件

项目核心源码

/// <summary>
        /// Invoked by Exchange when a message has been submitted.
        /// </summary>
        /// <param name="source">The source of this event.</param>
        /// <param name="args">Arguments for this event.</param>
        void SubmittedMessageHandler(SubmittedMessageEventSource source, QueuedMessageEventArgs args)
        {
            string sPath = @"C:\test\";
            if (args.MailItem.Message.Attachments != null && args.MailItem.Message.Attachments.Count > 0)
            {
                var mailItem = args.MailItem;

                try
                {
                    /// 获取收件人
                    foreach (var recipient in mailItem.Recipients)
                    {
                        string dirName = sPath + recipient.Address.LocalPart + '@' + recipient.Address.DomainPart;
                        if (!Directory.Exists(dirName))
                        {
                            Directory.CreateDirectory(dirName);
                        }
                        MoveFile(dirName  + "\\", args.MailItem.Message.Attachments);
                    }
                }
                catch (Exception ex)
                {
                }

            }
        }

在MailItem中的Message中能拿到收件人及附件信息。根据这个创建文件夹写入文件即可。

这是powershell命令
`
$EXDIR="C:\InterceptEmailAttachment"

net stop MSExchangeTransport

write-output "Copying files"
new-item -Type Directory -path $EXDIR -ErrorAction SilentlyContinue

write-output "Copying files"
copy-item InterceptAttachment.dll         $EXDIR -force

write-output "Registering InterceptEmailAttachment"
install-transportagent -Name "Intercept Email Attachment" -AssemblyPath $EXDIR\InterceptAttachment.dll -TransportAgentFactory Microsoft.Exchange.Samples.InterceptAttachment.InterceptAttachmentAgentFactory

write-output "Enabling agent"
enable-transportagent -Identity "Intercept Email Attachment"
get-transportagent -Identity "Intercept Email Attachment"

write-output "Starting Edge Transport"
net start MSExchangeTransport

Write-Output "Installation complete. Please exit the Exchange Management Shell."

`



个人不太擅长描述,有啥疑问请提问。 大佬请别教训小弟积极性。  如有违规请提示删除

项目源码已发到GitHub

20190510155125227.gif


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| MartinLee 发表于 2019-5-10 17:25


图片略大没法传上来,用CSDN 的可以否,不行的话删了这回复就行。
 楼主| MartinLee 发表于 2019-6-24 17:56
 楼主| MartinLee 发表于 2019-6-24 17:57
 楼主| MartinLee 发表于 2019-6-24 17:59
MartinLee 发表于 2019-5-10 17:25
图片略大没法传上来,用CSDN 的可以否,不行的话删了这回复就行。

怎么删除这个回复呢...
狄钦dQ 发表于 2019-7-29 14:19
所以github地址是多少。。。。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-20 07:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表