【问题标题】:Retrieved the email Address from the Exchange authenticated user从经过 Exchange 身份验证的用户检索电子邮件地址
【发布时间】:2020-08-17 13:44:27
【问题描述】:

在 VSTO 加载项中,我试图检索连接到 Outlook 的用户的电子邮件地址。出于安全原因,我想确保用户在使用电子邮件地址之前已通过 Exchange 服务器的身份验证。在域内或从外部使用 Outlook Anywhere 或类似的身份验证机制时,身份验证可以是直接的。 到目前为止,我有以下代码:

string authUserEmail = "";
string notAuthUserEmail = "";
AddressEntry currentUserAddressEntry = Application.Session.CurrentUser.AddressEntry;
if (currentUserAddressEntry.Type.Contains("Exchange"))
{
  ExchangeUser currentExUser = currentUserAddressEntry.GetExchangeUser();
  if(currentExUser != null)
    authUserEmail = currentExUser.PrimarySmtpAddress;
}
if (authUserEmail == "")
{
  string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
  notAuthUserEmail = currentUserAddressEntry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
}

我的问题是:

  1. 我可以依靠 GetExchangeUser() 函数来检索 Exchange 身份验证用户的详细信息吗?我阅读了here 的帖子,表明这可能是一个问题。
  2. 是否有更好的方法来检查用户是否通过了交换环境的身份验证? ExchangeConnectionMode 属性会更好吗?
  3. 如果我依赖 PropertyAccessor 属性,防止有人伪造其他人的电子邮件地址有多安全?

参考资料:

【问题讨论】:

    标签: c# vsto exchange-server outlook-addin office-addins


    【解决方案1】:

    您可以确定用户在之前的某个时间点已通过身份验证,至少在配置配置文件时是这样。

    【讨论】:

      【解决方案2】:

      看来您只需要在 Outlook 中获取当前用户的 SMTP 电子邮件地址。

      private string GetUserSMTPAddress()
      {
              string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
      
              Outlook.AddressEntry sender =
                  Application.Session.CurrentUser.AddressEntry;
              if (sender != null)
              {
                  //Now we have an AddressEntry representing the Sender
                  if (sender.AddressEntryUserType ==
                      Outlook.OlAddressEntryUserType.
                      olExchangeUserAddressEntry
                      || sender.AddressEntryUserType ==
                      Outlook.OlAddressEntryUserType.
                      olExchangeRemoteUserAddressEntry)
                  {
                      //Use the ExchangeUser object PrimarySMTPAddress
                      Outlook.ExchangeUser exchUser =
                          sender.GetExchangeUser();
                      if (exchUser != null)
                      {
                          return exchUser.PrimarySmtpAddress;
                      }
                      else
                      {
                          return null;
                      }
                  }
                  else
                  {
                      return sender.PropertyAccessor.GetProperty(
                          PR_SMTP_ADDRESS) as string;
                  }
              }
              else
              {
                  return null;
              }   
      }
      
      

      更多信息请参见Get the SMTP address of the sender of a mail item

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-11
        • 1970-01-01
        • 1970-01-01
        • 2023-03-22
        • 2017-05-12
        • 2012-11-26
        相关资源
        最近更新 更多