【问题标题】:Dynamics 365 Web API Email sendDynamics 365 Web API 电子邮件发送
【发布时间】:2018-05-07 03:29:33
【问题描述】:

我正在为网站上的页面建立订阅。因此,潜在订阅者通过表单发布帖子并被添加到 Dynamics 365 Online 中的营销列表中。

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

然后我需要向他们发送一封电子邮件,说明已使用此属性创建了一个新页面以及指向该页面的链接。

所以我想在 Dynamics 365 Online 中承担这个责任。

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

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

所以我在 CRM 中创建了一个电子邮件模板,它看起来就像代码找到了它!

这是我认为我要采取的行动: https://msdn.microsoft.com/en-us/library/mt607523.aspx

如果我查看 SOAP 服务上的文档,实际上有示例: https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.sendemailfromtemplaterequest.aspx?cs-save-lang=1&amp

但我要使用 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);

但我在发布时遇到异常:“电子邮件必须至少有一个收件人才能发送”。

可能是什么问题?

我认为文档位于: https://msdn.microsoft.com/en-us/library/mt607523.aspx

只需声明目标和相关的类型应该是“crmbaseentity”类型。一个基类...

有人知道是什么原因造成的吗?

这是电子邮件实体: https://msdn.microsoft.com/en-us/library/mt608007.aspx

对于“收件人”字段,可以阅读:“显示与收件人对应的电子邮件地址”。所以我不确定这是我应该使用的领域。如果文本是“带有“,将接收消息的分隔符的收件人”,我会更确定我必须使用这个字段。

更新: 好的,这就是您发布的内容:

{
 "email_activity_parties": [ 
    { "partyid_systemuser@odata.bind": "/systemusers(852a441c-b544-e611-80e3-c4346bc5e750)", "participationtypemask": 1 }, 
    { "partyid_systemuser@odata.bind": "/systemusers(852a441c-b544-e611-80e3-c4346bc5e750)", "participationtypemask": 2 }
  ],
 "description": "description lorem ipsum",
 "subject": "rubrik",
 "regardingobjectid_opportunity_email@odata.bind": "/opportunities(e9e6eb64-9c4c-e611-80e4-c4346bc58294)"
}

如果我想改变它以符合我的需要。我不认为我会利用机会。还是我必须? SendEmailFromTemplate Action 有三个参数:https://msdn.microsoft.com/en-us/library/mt607523.aspx TemplateId、关于和目标。我在下面更改了这段代码(未经测试)

{
 "TemplateId": "id-for-email-template",
 "Regarding": [ { "contactid@odata.bind": "/contacts(contact-guid-X)" } ],
 "Target": {
     "email_activity_parties": [ 
        { "partyid_systemuser@odata.bind": "/systemusers(systemuser-guid-Y)", "participationtypemask": 1 }, //1 is "sender"
        { "contactid@odata.bind": "/contacts(contact-guid-X)", "participationtypemask": 2 } // 2 is "to"
      ],
     "description": "description lorem ipsum",
     "subject": "rubrik",
     "contactid@odata.bind": "/contacts(contact-guid-X)"
    }
}

我会尝试这样的..

【问题讨论】:

  • 我认为我需要设置@odata.type...

标签: c# dynamics-crm microsoft-dynamics email dynamics-crm-365


【解决方案1】:

电子邮件是一个活动,所有活动将被拆分为活动指针+活动派对。 What you have to do 也将您用于regardingobject 的相同联系人放入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);

Ignoretorecipients 字段,仅使用 to

错误The e-mail must have at least one recipient before it can be sent 将消失。

更新:

我们必须在 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>)"));

【讨论】:

  • 我见过很多这样的例子,但没有 Web API 例子。 JSON 帖子会是什么样子?
  • 好的,我在我的主要帖子中做了更新。我想我必须改变几件事。将进行一些测试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-14
  • 2016-11-30
相关资源
最近更新 更多