Lockszmith
Lockszmith

Reputation: 2550

How to determine if there is a valid Lync user by email using Lync SDK?

Given an eMail address, I am trying to determine if it is a valid user's signin address.

I've tried the code below, but it only works if the user has been queried by the Lync Client by the user before, otherwise the user is identified as Unknown.

using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Extensibility;

private bool IsLyncUser(string eMail, out Microsoft.Lync.Model.Contact imContact)
{
    var lyncClient = LyncClient.GetClient();
    imContact = lyncClient.ContactManager.GetContactByUri(eMail);

    if (null != imContact)
    {
        try
        {
            var sourceType = (ContactSourceTypes)imContact.Settings[ContactSetting.Source];
            return (ContactSourceTypes)0 != (ContactSourceTypes.ExchangeService | ContactSourceTypes.GlobalAddressList | sourceType);
        }
        catch
        {
            imContact = null;
        }
    }
    return false;
}

Questions:

  1. Why is the data only loaded when the user is queried via the Lync Client GUI?
  2. How can I "fetch" the data, so that it will be available when queried?
  3. Is there a better way to query if the email belongs to a valid Lync user?

Upvotes: 3

Views: 1618

Answers (1)

Tom Morgan
Tom Morgan

Reputation: 2365

I've seen this working OK. That is to say: using lyncClient.ContactManager.GetContactByUri() works fine for me, even if the address being queried isn't in the client's contact list (and hasn't been queried).

One of the things I am doing though is also subscribing to presence changes. I wonder if that's why it's working for me: it takes a while for non-loaded contacts to be looked up, so it might be that my code does initially return Unknown, and is then updated in the event.

Just to check also: you're ensuring that your email addresses are SIP-prefixed? (i.e in the format sip:[email protected]).

Upvotes: 1

Related Questions