crm操作电子邮件
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
/// <summary>
/// 电子邮件
/// </summary>
public class EmailHelper
{
public static readonly string entityName = "email";
public Guid emailId = Guid.Empty;
public IOrganizationService service;
/// <summary>
/// 创建电子邮件
/// </summary>
public void Create()
{
Entity en = new Entity();
en["subject"] = "电子邮件測试";
en["activityId"] = Guid.NewGuid();
emailId = service.Create(en);
}
/// <summary>
/// 异步发送电子邮件
/// </summary>
/// <param name="query">查询的条件</param>
public void BackgroundSendEmail(QueryBase query)
{
BackgroundSendEmailRequest request = new BackgroundSendEmailRequest();
request.Query = query;
BackgroundSendEmailResponse response = (BackgroundSendEmailResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
bool[] hasAttachments = response.HasAttachments;
}
/// <summary>
/// 检查是否应该将传入电子邮件提升到 Microsoft Dynamics CRM 系统
/// </summary>
/// <param name="messageId">消息id</param>
/// <param name="subject">主题</param>
public void CheckPromoteEmail(string messageId,string subject)
{
CheckPromoteEmailRequest request = new CheckPromoteEmailRequest();
request.MessageId = messageId;
request.Subject = subject;
CheckIncomingEmailResponse response = (CheckIncomingEmailResponse)service.Execute(request);
int reasonCode = response.ReasonCode;
bool shouldDeliver = response.ShouldDeliver;
}
/// <summary>
/// 发送批量电子邮件
/// </summary>
/// <param name="query">查询的条件</param>
/// <param name="templateId">模版id</param>
public void SendBulkMail(QueryBase query,Guid templateId)
{
WhoAmIRequest emailSenderRequest = new WhoAmIRequest();
WhoAmIResponse emailSenderResponse = service.Execute(emailSenderRequest) as WhoAmIResponse;
SendBulkMailRequest request = new SendBulkMailRequest();
request.Query = query;
request.Sender = new EntityReference() { LogicalName = "systemuser", Id = emailSenderResponse.UserId };
request.RequestId = Guid.Empty;
request.RegardingType = "systemuser";
request.TemplateId = templateId;
SendBulkMailResponse response = (SendBulkMailResponse)service.Execute(request);
}
/// <summary>
/// 使用模板发送电子邮件
/// </summary>
/// <param name="userId">发送人。用户id</param>
/// <param name="contractId">接收人,联系人id</param>
/// <param name="templateId">模版id</param>
public void SendEmailFromTemplate(Guid userId, Guid contractId, Guid templateId)
{
Entity fromEn = new Entity() { LogicalName = "systemuser",Id = userId };
Entity toEn = new Entity() { LogicalName = "contract", Id = contractId };
Entity emailEn = new Entity() { LogicalName = entityName };
emailEn["from"] = new Entity[] { fromEn };
emailEn["to"] = new Entity[] { toEn };
emailEn["subject"] = "电子邮件发送測试";
emailEn["directioncode"] = true;
SendEmailFromTemplateRequest request = new SendEmailFromTemplateRequest();
request.Target = emailEn;
request.TemplateId = templateId;
request.RegardingId = contractId;
request.RegardingType = "contract";
SendEmailFromTemplateResponse response = (SendEmailFromTemplateResponse)service.Execute(request);
Guid id = response.Id;
}
/// <summary>
/// 发送电子邮件
/// </summary>
public void SendEmail()
{
SendEmailRequest request = new SendEmailRequest();
request.EmailId = emailId;
request.IssueSend = true;
request.TrackingToken = "";
SendEmailResponse response = (SendEmailResponse)service.Execute(request);
string subject = response.Subject;
}
/// <summary>
/// 获取用于对存储在 Microsoft Dynamics CRM 数据库中的用户或队列的电子邮件凭据进行加密或解密的密钥
/// </summary>
public void GetDecryptionKey()
{
GetDecryptionKeyRequest request = new GetDecryptionKeyRequest();
GetDecryptionKeyResponse response = (GetDecryptionKeyResponse)service.Execute(request);
string key = response.Key;
}
/// <summary>
/// 删除电子邮件
/// </summary>
public void Delete()
{
service.Delete(entityName, emailId);
}
}
crm操作电子邮件的更多相关文章
- crm操作业务部门
using System; using System.Linq; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messag ...
- crm操作货币实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- crm操作权限
using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using System.Colle ...
- crm操作知识库文章实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft ...
- crm操作观点
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- crm操作安全角色
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using System.Co ...
- crm操作产品实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- crm操作销售订单实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Cr ...
- crm操作约会实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft ...
随机推荐
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.8. 配置用户环境
2.8.配置用户环境 2.8.1. 配置节点RAC1 配置grid用户环境变量: cat >> /home/grid/.bash_profile <<EOF export TM ...
- http://blog.csdn.net/jhg1204/article/details/45013987
http://blog.csdn.net/jhg1204/article/details/45013987
- 怎样编写高效android代码
基于Android相关设备作为嵌入式设备范畴,在书写App应用的时候要格外关注效率.而且受电池电量的限制.这就导致嵌入式设备有诸多考虑.有限处理能力.因此就要求我们尽量去写高效的代码. 本文讨论了非常 ...
- XDebug 教程
安装说明: PHP调试时,不得不提XDEBUG这个调试利器.学习PHP以来,几乎所有的问题我都利用它来解决. 首先关于如何安装,不在赘述,请自行google之.(需要特别注意的是:PHP5.2 和5. ...
- java源码阅读LinkedBlockingQueue
1类签名与简介 public class LinkedBlockingQueue<E> extends AbstractQueue<E> implements Blocking ...
- g++ 链接静态库命令应该放在最后
昨天编译去年写的FloorServer,居然一堆错误: chu@chu-laptop:/media/E/work/github/FloorServer/FloorServer$ makeg++ -g ...
- riched32.dll riched20.dll msftedit.dll 解析
摘要: 本文对Rich Edit控件底层消息机制进行了讲解,以期读者对Windows平台下的Rich Edit控件有一个更深入的认识,同时对于使用Win32 SDK进行开发的人员具有一定参考价值.因为 ...
- Vue creatElement
1.传统template写法 <!DOCTYPE html> <html lang="zh"> <head> <meta charset= ...
- Ant 风格路径表达式(转)
ANT通配符有三种: 通配符 说明 ? 匹配任何单字符 * 匹配0或者任意数量的字符 ** 匹配0或者更多的目录 例子: URL路径 说明 /app/*.x 匹配(Matches)所有在app路径下的 ...
- Java基础知识介绍
数组的定义及初始化方式 数组对象创建没有() 一维数组 静态初始化: String[] books = {"Thinking in Java","Effective Ja ...