【发布时间】:2016-04-06 18:00:25
【问题描述】:
我正在尝试使用服务帐户访问“通知”电子邮件地址的收件箱。这个服务账号和我的账号有相同的访问权限,但是没有自己的邮箱,只是一个服务账号。当我使用我的帐户时,以下测试代码有效,但是当我使用服务帐户时,我收到以下错误:
当以没有邮箱的帐户发出请求时,您 必须为任何可区分的邮箱指定邮箱主 SMTP 地址 文件夹 ID。
此代码目前应该只显示收件箱中有多少封电子邮件的主题为“测试”。我已经尝试了该站点上许多帖子的建议答案,但没有一个有效。谢谢你的帮助。下面是代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("ServiceAccount", "Password");
service.AutodiscoverUrl("ScriptNotifications@domain.com", RedirectionUrlValidationCallback);
ItemView mView = new ItemView(10);
mView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
string querystring = "subject:\"test\"";
Console.WriteLine("Total emails whos subject is 'test':");
FindItemsResults<Item> results = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("ScriptNotifications@domain.com")), querystring, mView);
Console.WriteLine(results.Items.Count.ToString());
更新:
我想添加 Noonand 的代码,因为这给了我一个不同的错误。编辑以适应一个块而不是使用方法,这里是代码:
ImpersonatedUserId impersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "smtp.mysmtpaddress.com");
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential("ServiceAccount", "Password");
service.ImpersonatedUserId = impersonatedUserId;
service.AutodiscoverUrl("ScriptNotifications@domain.com", RedirectionUrlValidationCallback);
try
{
AlternateIdBase response =
service.ConvertId(new AlternateId(IdFormat.EwsId, "Placeholder", "ScriptNotifications@domain.com"), IdFormat.EwsId);
}
catch (ServiceResponseException)
{
// Expected exception, see EWS documentation
// Nonetheless, the credentials provided can authenticate successfully against this Exchange box
}
ItemView mView = new ItemView(10);
mView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
string querystring = "subject:\"test\"";
Console.WriteLine("Total emails whos subject is 'test':");
FindItemsResults<Item> results = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("ScriptNotifications@domain.com")), querystring, mView);
Console.WriteLine(results.Items.Count.ToString());
当我运行该代码时,我在“FindItemResults”行收到以下错误:
SMTP 地址没有与之关联的邮箱。
更新 2:
感谢 Noonand,我相信该错误是 Exchange Server 2013 本身的错误。链接见下:
https://support.microsoft.com/en-us/kb/3006861
我必须等到公司的变更流程完成后才能进行此更新,这可能需要很长时间,但我想将其发布出去,以便其他有相同问题的人可以看到并获得帮助.
【问题讨论】: