c# - EWS 减少邮箱连接时间
问题描述
我有一个用于读取传入邮件 Outlook(Exchange Server 2016)的程序,该程序使用帐户“system”在任务调度程序窗口中运行,但在连接步骤中,程序等待几分钟。如果程序开始使用域帐户,则连接是在没有预期的情况下进行的。我不想更改任务计划程序窗口中的设置。我认为问题出在连接超时,如何减少连接时间并在域授权后开始搜索邮箱?
我在连接时使用它:
string url = "Url";
string UserLogin = "UserLogin";
string UserPassword = "UserPassword";
string UserDomain = "UserDomain";
string UserEmail = "UserEmail";
ExchangeService ews = new ExchangeService();
UserPrincipal userP = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain, UserDomain, UserLogin, UserPassword), Environment.UserName);
ews.Credentials = new WebCredentials(UserLogin, UserPassword, UserDomain);
Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRedirectionUrlValidationCallback RedirectionUrlValidationCallback = null;
ews.AutodiscoverUrl(UserEmail, RedirectionUrlValidationCallback);
Folder inbox = Folder.Bind(ews, WellKnownFolderName.Inbox);
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Body);
解决方案
我会从
UserPrincipal userP = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain, UserDomain, UserLogin, UserPassword), Environment.UserName);
EWS 代码不需要它,我看不到您使用它返回的对象。您可以使用秒表https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch?view=netframework-4.8并为每一行代码计时并将其写入日志文件以查看位置延迟它。
您可以做的其他测试(如果有区别的话)是硬编码 EWS 端点并删除自动发现操作(默认情况下,这会执行几个 DNS 和 LDAP 查询来计算端点,所以请尝试)
string url = "Url";
string UserLogin = "UserLogin";
string UserPassword = "UserPassword";
string UserDomain = "UserDomain";
string UserEmail = "UserEmail";
string EwsEndpoint = "https://yourserver.youneedtodefine.com/EWS/Exchange.asmx";
ExchangeService ews = new ExchangeService();
ews.Credentials = new WebCredentials(UserLogin, UserPassword, UserDomain);
ews.Url = new Uri(EwsEndpoint);
Folder inbox = Folder.Bind(ews, WellKnownFolderName.Inbox);
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Body);
推荐阅读
- django - 当我打开模型时,会自动替换一个字段值
- python - Python3 - RtMidi - 输入回调不起作用
- php - Laravel:在 Trix 编辑器中上传图像时不支持获取请求。虽然方法是 POST
- mysql - 无法连接到 mysql 工作台中的本地主机
- java - 如何从字符串中提取子字符串直到换行符
- reactjs - 更改 react-data-table-component 中的默认文本
- java - 多次调整大小时,带有 autoSizeText 的 TextView 无法正常工作
- angular - 订阅元素位置的更改检测
- angular - 使用 Angular 进行 Twilio 视频 + 文本聊天
- reactjs - reactjs 理解以下语法的调度