使用CRM 4.0 SDK一次向多个联系人发送电子邮件

时间:2011-03-21 14:07:28

标签: email crm dynamics-crm-4

是否可以发送包含“收件人”字段中指定的多个电子邮件地址的电子邮件?我有它适用于单个收件人,但无法弄清楚如何发送到多个,这是我当前用于通过电子邮件发送单个用户的代码:

 public static void sendCRMNotification(string userGuid, string emailSubject, string emailBody, string recipientType) 

{  

//Set up CRM service
crmService crmservice = GetCrmService();

// 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(/*guid of sending user*/);

//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(userGuid);

//Create a new email
email emailInstance = new email();

//set email parameters
emailInstance.from = new activityparty[] { fromParty };
emailInstance.to = new activityparty[] { toParty };
emailInstance.subject = emailSubject;
emailInstance.description = emailBody;

//Create a GUId for the email
Guid emailId = crmservice.Create(emailInstance);

//Create a SendEmailRequest
SendEmailRequest request = new SendEmailRequest();
request.EmailId = emailId;
request.IssueSend = true;
request.TrackingToken = "";

 //Execute request
crmservice.Execute(request);
}

1 个答案:

答案 0 :(得分:2)

这是我过去所做的。在将数组设置为电子邮件属性之前,请在开头创建数组。

activityparty[] toParty = new activityparty[2];
    toParty[0] = new activityparty();
    toParty[0].partyid = new Lookup(EntityName.contact.ToString(), userGuid);

    toParty[1] = new activityparty();
    toParty[1].partyid = new Lookup(EntityName.contact.ToString(), anotherUserGuid);

    emailMessage.to = toParty;