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

发布于 2024-12-13 10:20:14 字数 905 浏览 5 评论 0原文

给定一个电子邮件地址,我试图确定它是否是有效的用户登录地址。

我已经尝试过下面的代码,但只有在用户之前已被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;
}

问题:

  1. 为什么仅在通过 Lync 客户端 GUI 查询用户时才加载数据?
  2. 如何“获取”数据,以便在查询时可用?
  3. 有没有更好的方法来查询电子邮件是否属于有效的 Lync 用户?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花易冷人易散 2024-12-20 10:20:14

我已经看到这个工作正常。也就是说:使用 lyncClient.ContactManager.GetContactByUri() 对我来说效果很好,即使正在查询的地址不在客户端的联系人列表中(并且尚未被查询)。

我正在做的一件事也是订阅状态更改。我想知道这是否是它对我有用的原因:查找未加载的联系人需要一段时间,因此可能我的代码最初返回未知,然后在事件中更新。

另外还要检查一下:您是否确保您的电子邮件地址带有 SIP 前缀? (即格式为 sip:[电子邮件受保护])。

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]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文