2011-03-21 55 views
1

是否可以发送包含在“to”字段中指定的多个电子邮件地址的电子邮件?我有工作单收件人,但无法弄清楚如何发送到多个,这里是我的电子邮件单个用户当前代码:使用CRM 4.0 SDK一次向多个联系人发送电子邮件

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); 
} 

回答

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; 
+0

感谢bweaver,我会给它一个镜头! – PercivalMcGullicuddy 2011-03-21 14:33:46

相关问题