6

Here is my code for searching contact by preferred mail.

using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
{
    try
    {
        var queryable = client.Contacts
            .Where(c => c.GetFacet<EmailAddressList>(EmailAddressList.DefaultFacetKey).PreferredEmail
            .SmtpAddress != string.Empty).OrderByDescending(c => c.LastModified).WithExpandOptions(new ContactExpandOptions(EmailAddressList.DefaultFacetKey));

        var enumerator = queryable.GetBatchEnumeratorSync(20);

        while (enumerator.MoveNext())
        {
            if (enumerator.Current != null)
            {
                foreach (var contact in enumerator.Current)
                {
                    if (contact.Emails() != null)
                    {
                        var email=contact.Emails().PreferredEmail.SmtpAddress;
                    }
                }
            }
        }
    }
    catch (XdbExecutionException ex)
    {
        AnalyticsHelpers.SitecoreLogException(ex);
    }
}

If I use here SmtpAddress == "sss@sss.com" I dont get any contact. Though those contacts are showing in experience profile.

If I use SmtpAddress != string.Empty I am getting lots of contacts and one of contact's email address is sss@sss.com.

How to get only those contacts which preferred email address is sss@sss.com?

Also after checking some code, I have found that if I find that even if I use SmtpAddress == "sss@sss.com" the query still take this contact.

  • 1
    I think you need to change this one: .WithExpandOptions(new ContactExpandOptions(PersonalInformation.DefaultFacetKey)) with EmailAddressList.DefaultFacetKey – Vlad Iobagiu Apr 12 '18 at 13:02
  • update my question – Anik Saha Apr 12 '18 at 14:18
3

SmtpAddress is [PIISensitive]

Indexing of PII sensitive data is disabled by default.

[Serializable]
public class EmailAddress
{
    public EmailAddress(string smtpAddress, bool validated)
    {
        this.SmtpAddress = smtpAddress;
        this.Validated = validated;
    }

    public int BounceCount { get; set; }

    [PIISensitive]
    public string SmtpAddress { get; set; }

    public bool Validated { get; set; }
}

In order to include it you have to set IndexPIISensitiveData to true as shown:

https://doc.sitecore.net/developers/xp/xconnect/xconnect-search-indexer/enable-pii-indexing.html#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.