Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 将帐户联系人列表放入电子邮件中的“抄送”字段_Email_Plugins_Dynamics Crm 4 - Fatal编程技术网

Email 将帐户联系人列表放入电子邮件中的“抄送”字段

Email 将帐户联系人列表放入电子邮件中的“抄送”字段,email,plugins,dynamics-crm-4,Email,Plugins,Dynamics Crm 4,我的任务是在crm 4中制作一个插件,它应该是1。在电子邮件的主题字段中输入帐户名,然后输入2。将帐户联系人列表放入电子邮件的“抄送”字段。 我做的第一件事很管用,但第二件。。。没有那么多。。。 我看到了一些样品,但没有一个接近我。。。 我想得到帮助并解释如何找到属于该帐户的联系人列表,然后将该列表放入“抄送”字段。 这是开始…: namespace mail { public class Class1 : IPlugin { public void Execute(IPlugi

我的任务是在crm 4中制作一个插件,它应该是1。在电子邮件的主题字段中输入帐户名,然后输入2。将帐户联系人列表放入电子邮件的“抄送”字段。 我做的第一件事很管用,但第二件。。。没有那么多。。。 我看到了一些样品,但没有一个接近我。。。 我想得到帮助并解释如何找到属于该帐户的联系人列表,然后将该列表放入“抄送”字段。 这是开始…:

namespace mail
{
public class Class1 : IPlugin
{
        public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;

            if (context.InputParameters.Properties.Contains("Target") &&
               context.InputParameters.Properties["Target"] is DynamicEntity)
            {
                entity = (DynamicEntity)context.InputParameters.Properties["Target"];

                if (entity.Name != EntityName.account.ToString())
                {
                    return;
                }
            }
            else
            {
                return;
            }

            try
            {
                // updating the subject of the email
                ICrmService service = context.CreateCrmService(true);
                account accountRecord = (account)service.Retrieve("account", ((Key)entity.Properties["accountid"]).Value, new ColumnSet(new string[] { "name" }));
                String str = String.Empty;
                str = accountRecord.name.ToString();
                DynamicEntity followup = new DynamicEntity();
                followup.Name = EntityName.email.ToString();

                followup.Properties = new PropertyCollection();
                followup.Properties.Add(new StringProperty("subject", str));

                //updating the CC of the email

                TargetCreateDynamic targetCreate = new TargetCreateDynamic();
                targetCreate.Entity = followup;

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

                CreateResponse created = (CreateResponse)service.Execute(create);
            }
            catch
            {
                throw new InvalidPluginExecutionException(
                      "An error occurred in the AccountUpdateHandler plug-in.");
            }
        }
    }
}

你可以试试这样的

List<BusinessEntity> contactList = GetNeededContacts(crmService, sourceEntity);
email targetEmail = GetTargetEmail(crmService, emailid);            
foreach (DynamicEntity contact in contactList)
            {
                activityparty contActParty = new activityparty() { partyid = new Lookup("contact", contact.contactid.Value };
                List<activityparty> tmpList = targetEmail.cc.ToList();
                tmpList.Add(contActParty);
                targetEmail.cc = tmpList.ToArray();
            }
crmService.Update(targetEmail);
您只需开发该功能即可获得联系人、用户或帐户引用