How to confirm valid Lync Users with email address?

Proposed Answer How to confirm valid Lync Users with email address?

  • Saturday, April 07, 2012 1:41 AM
     
      Has Code

    Hi all,

    I would like to read the outlook mail's sender and confirm its a valid Lync user or not inorder to add to the contact list.

    I tried to check Unified Communication Type and Contact Type from the following code but the results are "Unknown" and "Person" respectively which I dont find the information needed to validate the email address.

    LyncClient client = LyncClient.GetClient();
    Contact contact = client.ContactManager.GetContactByUri("xxx@xxx.com");

    Can you please let me know the correct procedure to validate the email address?

All Replies

  • Sunday, April 08, 2012 8:30 AM
     
     Proposed Answer Has Code
    You should get  the contacts from the groups

    Contact _contact;
    string _contactUri;
    foreach(var group in _client.ContactManager.Groups)
    {
        foreach (var contact in group)
        {
            //this is the way you could get the Uri of the contacts
            _contact = contact;
            _contactUri = _contact.Uri;
        }
    }




    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

    • Proposed As Answer by MohamedSakr Sunday, April 08, 2012 9:02 AM
    •  
  • Sunday, April 08, 2012 12:25 PM
     
     

    @MohamedSakr,

    Thanks for the reply, I think your post explains the  method to get the URI of the contatcs in the group but i need to find if an outlook email sender is a valid Lync user who may not be in the user's contact groups

    Venkz

  • Sunday, April 08, 2012 1:37 PM
     
     Proposed Answer

    If you could get the outlook email for the send well you could compare it with contacts in that groups but with adding "sip:" at the beginning 

    i.e. "sip:xxx@xxx.com"

    but if not in the groups you must get the status of the user from the Active Directory to know it is enabled to the Lync or not


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

    • Proposed As Answer by MohamedSakr Sunday, April 08, 2012 1:37 PM
    •  
  • Monday, April 09, 2012 2:39 PM
     
     
    Any updates

    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

  • Tuesday, April 10, 2012 1:42 AM
     
     

    Hi Mohamed,

    I am sorry, I fail to get the results even after adding "sip:" as the prefix. From my tests with both valid & invalid lync users who are not present in contact groups, the result appears to be "unknown" from the UnifiedCommunicationType of the contact. 

    Note: I am using ContactType  typecon = (ContactType)contact.GetContactInformation(ContactInformationType.ContactType); which results as Person and "UnifiedCommunicationType" property of the contact remains "Unknown"

    Is there any better way to get the status from the Active Directory as you said?

    Venkz

  • Tuesday, April 10, 2012 4:12 PM
     
     Proposed Answer Has Code

    Try this

    using System.DirectoryServices;
    
    void GetEnabledUsers()
    {
    DirectoryEntry myLdapConnection = createDirectoryEntry();
    
    DirectorySearcher search = new DirectorySearcher(myLdapConnection);
    search.PropertiesToLoad.Add("cn");
    search.Filter = "(&(objectClass=user) (| (msRTCSIP-UserEnabled=True) (msRTCSIP-PrimaryHomeServer=" + CurrentPool.ConfigurationsPath + ")))";
                    SearchResultCollection allUsers = search.FindAll();
    }


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

    • Proposed As Answer by MohamedSakr Tuesday, April 10, 2012 8:46 PM
    •  
  • Wednesday, April 11, 2012 1:49 PM
     
     

    updates?

    Are you tried the code i sent it to you


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

  • Thursday, June 07, 2012 5:10 AM
     
     Proposed Answer

    Hello VenkZ,

    Using the method GetContactByUri() with "sip:" plus email address won't work in this case because GetContactByUri() only accept valid Uri forms such as "sip:" or "tel:". if you use email address with a "sip:" prefix, this method will just create a contact with that sip address, which could be nonexistant.

    I think your question is rather how to resolve an email address in the Lync server to find out its corresponding sip address. Then you can use the LyncClient.ContactManager.BeginSearch() method to find the contact and it's sip address.

    The following code will do the job:

    Client.ContactManager.BeginSearch("foo.bar@consoto.com", SearchProviders.Default, SearchFields.EmailAddresses, SearchOptions.Default, 50, callback, null);

    // in the callback method, get the search result

    SearchResults results = Client.ContactManager.EndSearch(ar);

    Then you can find the sip address of the contact from the search results. You might want to double check that the email address of the contact matches the one you want to resolve.

    Thanks,

    Wei Wang [MSFT]