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 == "[email protected]" 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 [email protected].

How to get only those contacts which preferred email address is [email protected]?

Also after checking some code, I have found that if I find that even if I use SmtpAddress == "[email protected]" the query still take this contact.

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

1 Answer 1

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#

1
  • This id definitely correct answer Commented Jun 19, 2018 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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