3

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?
ccellar
  • 10,326
  • 2
  • 38
  • 56
Lockszmith
  • 2,173
  • 1
  • 29
  • 43

1 Answers1

1

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:user@domain.com).

Tom Morgan
  • 2,355
  • 18
  • 29
  • Thanks Tom, it's been a while since I posted this question, and you are the first to provide any feedback. I always use the SIP address format, yes. How do I subscribe to the presence changes? I'll need to try that. – Lockszmith Jun 23 '12 at 01:27
  • Subscribe to the `ContactInformationChanged` event of a contact. This gets raised for all sorts of things though, so for presence, check in the EventArgs that the ContactInformationType == Activity. You can then query the contact using GetContactInformation to retrieve the presence. – Tom Morgan Jul 02 '12 at 16:21
  • thanks @Tom, still haven't gotten to it, but now I know I'll try it, your solution sounds exactly like what I needed. – Lockszmith Jul 10 '12 at 11:48