C# Dynamics 365 Web API电子邮件发送

C# Dynamics 365 Web API电子邮件发送,c#,dynamics-crm,microsoft-dynamics,email,dynamics-crm-365,C#,Dynamics Crm,Microsoft Dynamics,Email,Dynamics Crm 365,我正在为网站上的页面建立订阅。因此,您可以通过表单成为订户帖子,并将其添加到Dynamics 365 Online的营销列表中 从网站的预定工作中,我然后向营销列表中的联系人发出请求 然后我需要给他们发送一封电子邮件,告诉他们已经用这个属性创建了一个新页面,并提供了一个指向该页面的链接 所以我想把这个责任放到网上 因此,我使用Web API和操作:SendEmailFromTemplate 不确定是否可以使用此操作或是否需要创建自定义操作 我需要传递页面的URL、标题和文本等数据。或者只有一个字

我正在为网站上的页面建立订阅。因此,您可以通过表单成为订户帖子,并将其添加到Dynamics 365 Online的营销列表中

从网站的预定工作中,我然后向营销列表中的联系人发出请求

然后我需要给他们发送一封电子邮件,告诉他们已经用这个属性创建了一个新页面,并提供了一个指向该页面的链接

所以我想把这个责任放到网上

因此,我使用Web API和操作:SendEmailFromTemplate 不确定是否可以使用此操作或是否需要创建自定义操作

我需要传递页面的URL、标题和文本等数据。或者只有一个字符串—包含所有这些内容的电子邮件正文

因此,我在CRM上创建了一个电子邮件模板,看起来就像代码找到了它一样

这就是我想要的行动:

如果我查看SOAP服务的文档,实际上有以下示例:

但是我要使用Web API

所以我试了一下:

dynamic regarding = new ExpandoObject();
var oppIndexer = regarding as IDictionary<string, Object>;
oppIndexer["contactid"] = contact.ContactId; //contact that will recive the 
email.
oppIndexer["@odata.type"] = "Microsoft.Dynamics.CRM.contact";

dynamic target = new ExpandoObject();
var targetIndexer = target as IDictionary<string, Object>;
targetIndexer["torecipients"] = "myemail@outlook.com";
targetIndexer["sender"] = "mysecondemail@businessname.com";
targetIndexer["inreplyto"] = "mysecondemail@businessname.com";
targetIndexer["subject"] = "This is the subject";
targetIndexer["description"] = "This should be the body of the email";
targetIndexer["directioncode"] = true; //outgoing
targetIndexer["@odata.type"] = "Microsoft.Dynamics.CRM.email";

dynamic sendEmailFromTemplate = new ExpandoObject();
sendEmailFromTemplate.TemplateId = Guid.Parse("my-email-template-guid-inserted-here");
sendEmailFromTemplate.Regarding = regarding;
sendEmailFromTemplate.Target = target;

api.ExecuteAction("SendEmailFromTemplate", sendEmailFromTemplate);
如果我想改变它,使它适合我的需要。我认为我不会利用机会。还是我必须?SendEmailFromTemplate操作有三个参数: TemplateId,关于和目标。我在下面稍微修改了这段代码(未测试)


我将尝试这样的方法。

电子邮件是一项活动,所有活动都将分为活动指针+活动方。将与您用于
关于对象的
相同的联系人也放入
toParty

//create activityparty
 Entity Fromparty = new Entity("activityparty");
 Entity Toparty = new Entity("activityparty");

//To set to Contact
Toparty["partyid"]= new EntityReference("contact", _ contactid));

//From set to User
Fromparty["partyid"]= new EntityReference("systemuser", _From));

//create email Object and set attributes
Entity email = new Entity("email");

email["from"] = new Entity[] { Fromparty };
email["to"] = new Entity[] { Toparty };
email["directioncode"] = true;

//setting the Regarding as Contact
email["regardingobjectid"] = new EntityReference("contact", _contactid);
torecipients
字段,仅使用
to

错误
电子邮件必须至少有一个收件人才能发送
将消失

更新:

我们必须在web api方面使用导航属性

//Create email
var email = new JObject(
           new JProperty("email_activity_parties",
             new JArray(
                  new JObject(
                          new JProperty("partyid_systemuser@odata.bind", "/systemusers (<guid>)"),
          new JProperty("participationtypemask", 1)),
                     new JObject(
                           new JProperty("partyid_systemuser@odata.bind", "/systemusers(<guid>)"),
                   new JProperty("participationtypemask", 2)))),
                  new JProperty("description", txtEmail.Text.Replace("\r\n","<br>")),
                  new JProperty("subject", "Test Subject"),
                  new JProperty("regardingobjectid_opportunity_email@odata.bind", "/opportunities(<guid>)"));
//创建电子邮件
var email=newjobject(
新的JProperty(“电子邮件\活动\各方”,
新杰瑞(
新作业项目(
新JProperty(“partyid_systemuser@odata.bind“,”/systemusers()”,
新JProperty(“participationtypemask”,1)),
新作业项目(
新JProperty(“partyid_systemuser@odata.bind“,”/systemusers()”,
新的JProperty(“participationtypemask”,2)),
新JProperty(“description”,txtEmail.Text.Replace(“\r\n“,”
”)), 新JP财产(“受试者”、“受试者”), 新的JProperty(“考虑到客观的机会_email@odata.bind“,”/opportunities()”);
我看过很多这样的例子,但没有Web API的例子。JSON帖子会是什么样子?好的,我在我的主要帖子上做了更新。我想我必须改变一些事情。将进行一些测试。我需要设置@odata.type我想。。。
//create activityparty
 Entity Fromparty = new Entity("activityparty");
 Entity Toparty = new Entity("activityparty");

//To set to Contact
Toparty["partyid"]= new EntityReference("contact", _ contactid));

//From set to User
Fromparty["partyid"]= new EntityReference("systemuser", _From));

//create email Object and set attributes
Entity email = new Entity("email");

email["from"] = new Entity[] { Fromparty };
email["to"] = new Entity[] { Toparty };
email["directioncode"] = true;

//setting the Regarding as Contact
email["regardingobjectid"] = new EntityReference("contact", _contactid);
//Create email
var email = new JObject(
           new JProperty("email_activity_parties",
             new JArray(
                  new JObject(
                          new JProperty("partyid_systemuser@odata.bind", "/systemusers (<guid>)"),
          new JProperty("participationtypemask", 1)),
                     new JObject(
                           new JProperty("partyid_systemuser@odata.bind", "/systemusers(<guid>)"),
                   new JProperty("participationtypemask", 2)))),
                  new JProperty("description", txtEmail.Text.Replace("\r\n","<br>")),
                  new JProperty("subject", "Test Subject"),
                  new JProperty("regardingobjectid_opportunity_email@odata.bind", "/opportunities(<guid>)"));