我正在将我的旧 Sitecore (< 8) 代码转换为与 Sitecore EXM 一起使用。我很难从代码中将用户添加到收件人列表中。这篇文章中的答案:Sitecore 8 EXM add a contact to list from listmanager没有完全回答我的问题,由于我无法发表评论,我决定开始一个新话题。
我的第一个问题是我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 个订阅者。
对此有什么想法吗?