自动发现用户名!= email-address的交换。使用URN而不是域\用户名?

时间:2014-11-26 17:37:49

标签: c# exchange-server exchangewebservices

我有一封电子邮件,我尝试通过Microsoft.Exchanage.WebServices访问。具体来说,我试图自动发现网址。我在Microsoft远程连接分析器中运行以下命令(这可以):

Email address: foooosoft.fiiztestmailbox@baaar.eu
Domain\User Name (or UPN): baaarnet\foooosoft.fiiztestma
         (foooosoft.fiiztestmailbox@baaar.eu also works)
Password: password1

这是因为我的用户名是foooosoft.fiiztestma,因为SAMAccountNames的长度限制(20个字符)。

尝试使用我的电子邮件地址作为帐户名会导致401错误。如何更改我的代码以将其考虑在内?

我试图提供" foooosoft.fiiztestma"到WebCredentials构造函数,但我得到了同样的错误。

或者,有没有办法切断追逐并只提供UPN(电子邮件地址)而不是使用domainname \ username?

public class Program
{
    public static void Main(string[] args)
    {
        string emailUser = "foooosoft.fiiztestmailbox@baaar.eu";
        string password = "password1";
        string domain = "baaarnet";

        var credentials = new WebCredentials(emailUser, password, domain);

        var foo = new ExchangeService
        {
            Credentials = credentials,
            Url = DiscoverExchangeUrl(emailUser, credentials),
            TraceEnabled = false
        };
    }

    private static Uri DiscoverExchangeUrl(string emailAddress, ExchangeCredentials credentials)
    {
        var autoDiscover = new AutodiscoverService
        {
            Credentials = credentials,
            EnableScpLookup = false,
            RedirectionUrlValidationCallback = url => true,
            TraceEnabled = false
        };

        var userSettings = autoDiscover.GetUserSettings(emailAddress, UserSettingName.ExternalEwsUrl);
        return new Uri(userSettings.Settings[UserSettingName.ExternalEwsUrl].ToString());
    }

}

1 个答案:

答案 0 :(得分:1)

我很幸运提供了UPN作为用户名和域名的空字符串。