简体   繁体   English

如何使用Lync SDK通过电子邮件确定是否存在有效的Lync用户?

[英]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. 我已经尝试过下面的代码,但只有在用户之前由Lync客户端查询过用户才会生效,否则用户将被识别为“未知”。

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? 为什么仅在通过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? 有没有更好的方法来查询电子邮件是否属于有效的Lync用户?

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). 也就是说:使用lyncClient.ContactManager.GetContactByUri()对我来说很好,即使被查询的地址不在客户端的联系人列表中(并且尚未被查询)。

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. 我想知道这是不是为什么它对我有用:查找非加载联系人需要一段时间,因此可能是我的代码最初返回Unknown,然后在事件中更新。

Just to check also: you're ensuring that your email addresses are SIP-prefixed? 还要检查一下:您确保您的电子邮件地址是SIP加前缀的吗? (ie in the format sip:user@domain.com). (即格式为sip:user@domain.com)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM