我必须连接到交换服务器邮件的收件箱并到达邮件中的附件。我有这部分代码,在控制台应用程序中调试时没有问题。我创建了一个Windows服务来检查邮箱并定期获取附件。但是,Windows服务无法创建凭据会引发异常。请检查此计划并与我分享您的想法。我在Windows服务上调试和运行时有什么区别。
private FindItemsResults<Item> ConnectToInbox()
{
ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
_service.Credentials = new WebCredentials("username", "password");
_service.AutodiscoverUrl("mail@mail.com");
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FindItemsResults<Item> findResults = _service.FindItems(WellKnownFolderName.Inbox, new ItemView(1000));
Logger.Write("There is/are " + (findResults.Items.Count) + " email(s) in Inbox");
return findResults;
}