如何通过Windows登录名使用用户名和密码访问Outlook Exchange Server?

专门的学习者

我正在为我的公司使用VS19在WinForms中创建一个“简单” VSTO(Outlook插件),它将扫描所有文件夹中的社会保险号,并在listView中列出电子邮件项目,以便用户可以删除邮件。

我正在使用EWS托管API客户端:https : //docs.microsoft.com/zh-cn/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications ?redirectedfrom = MSDN

我已经实现了上述罚​​款,但问题是我不知道如何正确访问Exchange Server。在链接中提供的示例中,用户名和密码是硬编码的,并且由于这是一个发布给多个不同用户的应用程序,因此我想使用Windows登录名(这是我公司的同一登录名)来访问交换服务器。

using Microsoft.Exchange.WebServices.Data;

// Setup how to download emails from the exchange server
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("test.tester", "test123","domaintest");
service.AutodiscoverUrl("[email protected]");


// Add all the mails from exchange server (inbox) to a list
bool more = true;
ItemView view = new ItemView(int.MaxValue, 0, OffsetBasePoint.Beginning);
view.PropertySet = PropertySet.IdOnly;
FindItemsResults<Item> findResults;
List<EmailMessage> emails = new List<EmailMessage>();
while (more)
{
     findResults = service.FindItems(WellKnownFolderName.Inbox, view);
     foreach (var item in findResults.Items)
        {
        emails.Add((EmailMessage)item);
        }
        more = findResults.MoreAvailable;
        if (more)
        {
            view.Offset += 1000;
        }
}

当我将我的信息硬编码在上面的代码中时,一切正常,我可以访问收件箱文件夹并列出电子邮件列表

搜索了几个小时没有结果后,希望您能为我提供帮助。

尤金·阿斯塔菲耶夫(Eugene Astafiev)

如果您以本地Exchange服务器为目标,并且您的用户凭据已加入域:

service.UseDefaultCredentials = true;

假设本地凭据与邮箱关联,则以本地Exchange服务器为目标的加入域的客户端可以使用登录用户的默认凭据。在实例化ExchangeService对象之后,添加以下代码。

// Setup how to download emails from the exchange server
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl("[email protected]");

但是,如果您以Exchange Online或Office 365开发人员站点邮箱为目标,则必须传递显式凭据。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Powershell和Outlook从Exchange Server中获取项目?

如何实现Exchange Server的推送邮件通知?

使用Exchange Web服务和Windows身份验证连接到Exchange Server

如何使用OAuth2和Microsoft登录名和HTTP请求使用用户名/密码登录

使用用户名和登录名的SFTP?

从Exchange Server发送邮件

Exchange Server全局事件

使用Exchange Web服务(EWS)API查找Exchange Server版本的方法

如何使用MS Exchange Server发送电子邮件

Java Mail to Exchange Server“不支持登录方法”

Team Foundation Server 2018 用户缺少 Exchange 的联系信息

使用Java中的自动发现连接到Exchange Server

PowerShell - 使用 Exchange Server 2016 REST API 获取日历事件

使用 C# Powershell 获取 Exchange Server 的 MessageTrace

使用javamail在Exchange Server上无法与imap一起使用域/用户/帐户登录

如何使用2或3个用户名和密码以用户形式创建登录名?

如何使用登录名(用户名和密码),按钮更改活动?

iOS 8 Exchange Server DeviceId

如何使用C#在Exchange Server中获取日历的用户权限

如何通过MS Exchange Server用emacs发送电子邮件

如何通过Exchange Server的电子邮件在Unix上触发Shell脚本

如何通过 Outlook 兑换使用 Exchange Impersonation

自定义属性不会立即保存到 Outlook 桌面 2016 中的 Exchange Server

如何获取登录Jasper Server的用户的用户名?

能够在MS Exchange Server中将用户设置为忙/闲

使用AWS Cognito和React的仅限Facebook / Google的登录名(无用户名/密码)

通过电话号码从Exchange Server查询GAL联系人

通过EWS Exchange Server的“ StreamingSubscription”获得通知时,获取新接收到的电子邮件的ItemId。

是否有可以在MS Exchange Server中查找和清除信用卡号的软件?