Dynamics CRM邮件附件,你真的了解吗?



static void Main(string[] args)
{
var service = GetOrganizationService();
var fetchXML = string.Format(@"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false' no-lock='true' count='1'>
<entity name='email'>
<attribute name='subject' />
<attribute name='regardingobjectid' />
<attribute name='from' />
<attribute name='to' />
<attribute name='statuscode' />
<attribute name='activityid' />
<filter type='and'>
<condition value='微软MVP罗勇测试附件的邮件主题' attribute='subject' operator='eq' />
</filter>
</entity>
</fetch>");
EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (ec.Entities.Count == )
{
Console.WriteLine("邮件的ID是" + ec.Entities[].GetAttributeValue<Guid>("activityid") + "下面是附件信息:");
QueryExpression query = new QueryExpression
{
EntityName = "activitymimeattachment",
ColumnSet = new ColumnSet("filename","subject","filesize","mimetype","activityid","activitymimeattachmentid","body"),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "objecttypecode",
Operator = ConditionOperator.Equal,
Values = {"email"}
},
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = {ec.Entities[].GetAttributeValue<Guid>("activityid")}
}
}
}
};
var i = ;
foreach (var entity in service.RetrieveMultiple(query).Entities)
{
Console.WriteLine("第" + i + "个附件:");
Console.WriteLine("filename:" + entity.GetAttributeValue<string>("filename"));
Console.WriteLine("filesize:" + entity.GetAttributeValue<int>("filesize"));
Console.WriteLine("mimetype:" + entity.GetAttributeValue<string>("mimetype"));
Console.WriteLine("subject:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("activityid:" + entity.GetAttributeValue<EntityReference>("activityid").Id);
Console.WriteLine("activitymimeattachmentid:" + entity.GetAttributeValue<Guid>("activitymimeattachmentid"));
Console.WriteLine("body:" + entity.GetAttributeValue<string>("body"));
Console.WriteLine("--------------------------------------------------"); i++;
}
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
运行结果如下,可以得知filesize应该是以字节为单位的,附件的内容应该是以base64编码后存储等等信息:


static void Main(string[] args)
{
var service = GetOrganizationService();
var fetchXML = string.Format(@"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false' no-lock='true' count='1'>
<entity name='email'>
<attribute name='subject' />
<attribute name='regardingobjectid' />
<attribute name='from' />
<attribute name='to' />
<attribute name='statuscode' />
<attribute name='activityid' />
<filter type='and'>
<condition value='微软MVP罗勇测试附件的邮件主题' attribute='subject' operator='eq' />
</filter>
</entity>
</fetch>");
EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (ec.Entities.Count == )
{
Console.WriteLine("邮件的ID是" + ec.Entities[].GetAttributeValue<Guid>("activityid") + "下面是附件信息:");
QueryExpression query = new QueryExpression
{
EntityName = "activitymimeattachment",
ColumnSet = new ColumnSet("filename","subject","filesize","mimetype","activityid","activitymimeattachmentid"),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "activityid",
Operator = ConditionOperator.Equal,
Values = {ec.Entities[].GetAttributeValue<Guid>("activityid")}
}
}
}
};
var i = ;
foreach (var entity in service.RetrieveMultiple(query).Entities)
{
Console.WriteLine("第" + i + "个附件:");
Console.WriteLine("filename:" + entity.GetAttributeValue<string>("filename"));
Console.WriteLine("filesize:" + entity.GetAttributeValue<int>("filesize"));
Console.WriteLine("mimetype:" + entity.GetAttributeValue<string>("mimetype"));
Console.WriteLine("subject:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("activityid:" + entity.GetAttributeValue<EntityReference>("activityid").Id);
Console.WriteLine("activitymimeattachmentid:" + entity.GetAttributeValue<Guid>("activitymimeattachmentid"));
Console.WriteLine("--------------------------------------------------");
i++;
}
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
static void Main(string[] args)
{
var service = GetOrganizationService();
WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
WhoAmIResponse whoAmIResponse = service.Execute(whoAmIRequest) as WhoAmIResponse;
Entity fromEntity = new Entity("activityparty");
fromEntity["partyid"] = new EntityReference("systemuser", whoAmIResponse.UserId);
Entity toEntity = new Entity("activityparty");
toEntity["partyid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
Entity emailEntity = new Entity("email");
emailEntity["to"] = new Entity[] { toEntity };
emailEntity["from"] = new Entity[] { fromEntity };
emailEntity["subject"] = "微软MVP罗勇测试邮件使用现有附件";
emailEntity["description"] = "<a href='http://sugege.top'>素格格新疆特产店</a>";
var emailId = service.Create(emailEntity);
var activityMimeAttachment = new Entity("activitymimeattachment");
activityMimeAttachment["objectid"] = new EntityReference("email",emailId);
activityMimeAttachment["objecttypecode"] = "email";
activityMimeAttachment["filename"] = "sugege.png";//不设置这个字段的值,附件不会显示文件名
activityMimeAttachment["filesize"] = ;//设置了这个字段的值,附件也不会显示文件大小(字节),囧
activityMimeAttachment["attachmentid"] = new Guid("b8ef5a55-1872-e511-80e6-000d3a804b9b");//该字段不能使用new EntityReference类型来赋值
service.Create(activityMimeAttachment);
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}

但是我如果查询这个邮件的附件信息会发现有点儿不同,比如filesize为0,mimetype为空值,囧。

static void Main(string[] args)
{
var service = GetOrganizationService();
WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
WhoAmIResponse whoAmIResponse = service.Execute(whoAmIRequest) as WhoAmIResponse;
Entity fromEntity = new Entity("activityparty");
fromEntity["partyid"] = new EntityReference("systemuser", whoAmIResponse.UserId);
Entity toEntity = new Entity("activityparty");
toEntity["partyid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
Entity emailEntity = new Entity("email");
emailEntity["to"] = new Entity[] { toEntity };
emailEntity["from"] = new Entity[] { fromEntity };
emailEntity["subject"] = "微软MVP罗勇测试邮件使用新附件";
emailEntity["description"] = "<a href='http://sugege.top'>素格格新疆特产店</a>";
var emailId = service.Create(emailEntity);
var activityMimeAttachment = new Entity("activitymimeattachment");
activityMimeAttachment["objectid"] = new EntityReference("email", emailId);
activityMimeAttachment["objecttypecode"] = "email";
activityMimeAttachment["subject"] = "附件示例";
activityMimeAttachment["filename"] = "mvpluoyong.txt";//不设置这个字段的值,附件不会显示文件名
activityMimeAttachment["body"] = System.Convert.ToBase64String(new UTF8Encoding().GetBytes(@"微软MVP罗勇测试邮件使用新附件"));
service.Create(activityMimeAttachment);
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}


Dynamics CRM邮件附件,你真的了解吗?的更多相关文章
- dynamics crm 365 附件上传图片并且显示。
参考了几篇博客做的: 新增websource文件(html): <!DOCTYPE html> <html> <head> <title>注释</ ...
- Dynamics CRM中的注释(Note)及RollupRequest消息初探
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复161或者20151015可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释,这个实体的架构名称是Ann ...
- Dynamics CRM 2013开始推出的服务器端同步来配置邮件服务
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 为Dynamics CRM的Office附件注释定制个无需下载即可在线查看的功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复164或者20151021可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 上一篇博客:为Dynamics ...
- 为Dynamics CRM注释的图片附件做个预览功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复163或者20151017可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! Dynamics CRM中注释可 ...
- Dynamics CRM 2016 的新特性
新版本CRM (2016 with update 0.1) 发布已有几个月了,总结一下新特性,从几个方面来看: 1. 针对整合功能的新特性 (1) 增加了CRM App for Outlook. 这个 ...
- Dynamics CRM中的操作(action)是否是一个事务(transaction)?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复168或者20151104可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 以前的博文 微软Dynamics ...
- C# MailMessage Attachment 中文名附件发邮件-Firefox中文显示正常,网页打开邮件附件中文名乱码
一.故事 首先通过CDO.Message来获取邮件EML相关数据:邮件标题.邮件内容.邮件附件.发件人.收件人.CC主要就这么几个,其次通过MailMessage来组织邮件通过Python来发送邮件! ...
- Dynamics CRM模拟OAuth请求获得Token后在外部调用Web API
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复233或者20161104可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
随机推荐
- Android App内文档展示方案整理
一.Word.Excel.PPT 展示 1. 微软Office公开Api接口 如果文档内容不是很机密或者只是需要实现预览文档的话,可以考虑使用微软的公共Api接口实现. 微软Office公开Api地址 ...
- Mac 安装nginx之后重启、停止、开启等操作
操作系统:macOs High Sierra 10.13.6 1.我用的homebrew安装的nignx1.15.9,安装完成之后会有下面的提示: 网站根目录在:/usr/local/var/www ...
- 2019有赞中高级Java工程师面试题与解答
说说JVM的内存分区 线程私有的区域 程序计数器:JVM中程序计数器相当于汇编语言中的CPU中的寄存器,保存程序当前执行的指令的地址. 虚拟机栈:Java方法执行的栈由许多个栈帧构成,每个栈帧对应一个 ...
- 【nagios监控】基于linux搭建nagios监控
nagios工作原理 nagios的功能是监控服务和主机,但是其自身并不包括这些功能,所有的监控.检测功能都是通过各种插件来完成的. 启动nagios后,它会周期性的自动调用插件去检测服务器状态,同时 ...
- Docker入门(四)——MySQL镜像中的数据库可视化
在详细介绍这篇文章的内容前,需要说明下笔者写这篇文章的意图:笔者在现有的开发中,前后端联调的方式为Docker镜像对接,数据库使用MySQL镜像,开发环境为远程服务器,因此,笔者迫切需要一种能将远 ...
- ES-入门
https://es.xiaoleilu.com/010_Intro/10_Installing_ES.html 1. 安装 https://www.elastic.co/cn/downloads/ ...
- Using the Security System 使用安全系统
In this lesson, you will learn how to use a Security System in the application. When you use this sy ...
- Navicat远程连接MySQL8,必知防坑策略
项目上线是每一个开发工程师面临收获前面抓紧时间开发的成果,但有时我们上线项目首先需要做一些相关的业务测试.通过Xshell远程连接后使用命令行的方式连接操作Mysql这个没什么太大的你问题.但每次通过 ...
- Andriod安卓下开发UHF读写器
随着在Andriod设备上使用UHF读写器变得越来越广泛,友我科技独立研发了UHF读写器的android开发包,使用此开发包,工程师只需在工程中导入jar包,使用java语言就可以轻松的开发出Andr ...
- std::map自定义类型key
故事背景:最近的需求需要把一个结构体struct作为map的key,时间time作为value,定义:std::map<struct, time> _mapTest; 技术调研:众所周知, ...