CRM 4.0 使用 API 发送电子邮件时遇到问题...请帮忙!

发布于 2024-10-19 00:41:38 字数 1745 浏览 5 评论 0原文

我正在尝试让 CRM 从 .Net C# 应用程序戏剧性地发送电子邮件。我想我已经很接近了,但我不断收到错误:

0x80040203 无法创建活动派对:应存在 partyid 或 addressused 字段平台

这是我的代码:

private static void sendCrmEmail()
    {
    try
    {
      //Set up the service
      CrmService crmservice = GetCrmService(OrganisationName, ServerAddress);

      Guid emailID = new Guid();

      // Create a FROM activity party for the email
      activityparty fromParty = new activityparty();
      fromParty.partyid = new Lookup();
      fromParty.partyid.type = EntityName.systemuser.ToString();
      fromParty.partyid.Value = new Guid("275462F3-1E73-DF11-828B-0050568F1812");


      //Create a TO activity party for email
      activityparty toParty = new activityparty();
      fromParty.partyid = new Lookup();
      fromParty.partyid.type = EntityName.contact.ToString();
      fromParty.partyid.Value = new Guid("81AEDF3D-E040-E011-9DA2-000C29E4BD21");  

      // Create an email message.
      email email = new email();

      // Set email properties
      email.to = new activityparty[] { fromParty };
      email.from = new activityparty[] { toParty };
      email.subject = "subject";
      email.description = "body";

      CrmBoolean direction = new CrmBoolean();
      direction.Value = true;
      email.directioncode = direction;

      TargetCreateEmail targetCreate = new TargetCreateEmail();
      targetCreate.Email = email;

      CreateRequest request = new CreateRequest();
      request.Target = targetCreate;

      CreateResponse response = (CreateResponse)crmservice.Execute(request);
      emailID = response.id;

    }
    catch (System.Web.Services.Protocols.SoapException ex)
    {
      Console.WriteLine(ex.Detail.InnerText);
    }


}

I am trying to get CRM to send an email melodramatically from a .Net C# app. I think I am close, but I keep getting an error:

0x80040203 Cannot create activity party: either partyid or addressused field should be present Platform

Here is my code:

private static void sendCrmEmail()
    {
    try
    {
      //Set up the service
      CrmService crmservice = GetCrmService(OrganisationName, ServerAddress);

      Guid emailID = new Guid();

      // Create a FROM activity party for the email
      activityparty fromParty = new activityparty();
      fromParty.partyid = new Lookup();
      fromParty.partyid.type = EntityName.systemuser.ToString();
      fromParty.partyid.Value = new Guid("275462F3-1E73-DF11-828B-0050568F1812");


      //Create a TO activity party for email
      activityparty toParty = new activityparty();
      fromParty.partyid = new Lookup();
      fromParty.partyid.type = EntityName.contact.ToString();
      fromParty.partyid.Value = new Guid("81AEDF3D-E040-E011-9DA2-000C29E4BD21");  

      // Create an email message.
      email email = new email();

      // Set email properties
      email.to = new activityparty[] { fromParty };
      email.from = new activityparty[] { toParty };
      email.subject = "subject";
      email.description = "body";

      CrmBoolean direction = new CrmBoolean();
      direction.Value = true;
      email.directioncode = direction;

      TargetCreateEmail targetCreate = new TargetCreateEmail();
      targetCreate.Email = email;

      CreateRequest request = new CreateRequest();
      request.Target = targetCreate;

      CreateResponse response = (CreateResponse)crmservice.Execute(request);
      emailID = response.id;

    }
    catch (System.Web.Services.Protocols.SoapException ex)
    {
      Console.WriteLine(ex.Detail.InnerText);
    }


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-10-26 00:41:38

您的 toParty 块只是重置 fromParty。它应该看起来像这样:

//Create a TO activity party for email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.contact.ToString();
toParty.partyid.Value = new Guid("81AEDF3D-E040-E011-9DA2-000C29E4BD21");

Your toParty block is just resetting the fromParty. It should look like this:

//Create a TO activity party for email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.contact.ToString();
toParty.partyid.Value = new Guid("81AEDF3D-E040-E011-9DA2-000C29E4BD21");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文