2015-10-27 107 views
1

我正在將我的舊Sitecore(< 8)代碼轉換爲Sitecore EXM。我很難從代碼中將用戶添加到收件人列表中。在這篇文章中的答案:Sitecore 8 EXM add a contact to list from listmanager沒有完全回答我的問題,因爲我不能評論,我決定開始一個新的話題。EXM訂閱列表C#

我的第一個問題是我的EcmFactory.GetDefaultFactory().Bl.RecipientCollectionRepository.GetEditableRecipientCollection(recipientListId)RecipientCollectionRepository上給出了編譯錯誤,它說它不存在。所以我使用了稍微不同的代碼。現在我的代碼,如下所示:

 var contactRepository = new ContactRepository(); 
     var contactName = this.Email.Text; 
     var contact = contactRepository.LoadContactReadOnly(contactName); 

     contact = contactRepository.CreateContact(Sitecore.Data.ID.NewID); 
     contact.Identifiers.AuthenticationLevel = Sitecore.Analytics.Model.AuthenticationLevel.None; 
     contact.System.Classification = 0; 
     contact.ContactSaveMode = ContactSaveMode.AlwaysSave; 
     contact.Identifiers.Identifier = contactName; 
     contact.System.OverrideClassification = 0; 
     contact.System.Value = 0; 
     contact.System.VisitCount = 0; 

     var contactPreferences = contact.GetFacet<IContactPreferences>("Preferences"); 
     contactPreferences.Language = "nl-NL"; 

     var contactEmailAddresses = contact.GetFacet<IContactEmailAddresses>("Emails"); 
     contactEmailAddresses.Entries.Create("test").SmtpAddress = this.Email.Text; 
     contactEmailAddresses.Preferred = "test"; 

     var contactPersonalInfo = contact.GetFacet<IContactPersonalInfo>("Personal"); 
     contactPersonalInfo.FirstName = contactName; 
     contactPersonalInfo.Surname = "recipient"; 
     if (recipientList != null) 
       { 
        var xdbContact = new XdbContactId(contact.ContactId); 

        if (!recipientList.Contains(xdbContact, true).Value) 
        { 
         recipientList.AddRecipient(xdbContact); 
        } 

        contactRepository.SaveContact(contact, new ContactSaveOptions(true, null)); 
       } 

所以recipientList被發現,並在第一時間我的聯繫人添加到它,它增加了「收件人」 1(使用/sitecore/system/List Manager/All Lists/E-mail Campaign Manager/Custom/RecipientList選中)。

我也有一個消息,它有這個選擇加入收件人列表,但是當我檢查該消息時,它表示它將被髮送給0個訂戶。

對此有何看法?

回答

0

請參閱本文列出已知問題Sitecore的EXM:「收件人後收件人總數已訂閱列表(62217)‘ https://kb.sitecore.net/articles/149565

’收件人列表中顯示爲」 0

我身邊這通過在消息中添加一個簡單列表(從csv,一個聯繫人)到沙盒環境中。這會將總收件人數從0增加到1,從而允許激活郵件。複合列表中的所有收件人都發送了一條消息。

0

你有分佈式環境嗎?如果是這樣,RecipientCollectionRepository將無法正常工作,因爲它僅在Content Management服務器上可用。您可以嘗試使用ClientApi:

ClientApi.UpdateSubscriptions(RecipientId recipientId, string[] listsToSubscribe, string[] listsToUnsubscribe, string managerRootId, bool confirmSubscription) 

只需將要訂閱人員列表的ID添加到第一個字符串數組中即可。

只需使用此選項快速記下,listToUnsubscribe實際上不會從列表中刪除聯繫人。您打算通過退出列表的ID。這基本上將它們排除在未來的電子郵件之外。一個缺點是你將不能再重新訂閱它們。

如果這不適合你,你需要在CM服務器使用recipientCollectionRepository訂閱和取消訂閱

您的CD服務器和CM服務器之間創建自己的API