2011-03-21 61 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

相關問題