我需要使用Exchange Web服务API发送邮件,然后检查它们是否已发送。为此,我尝试使用EWS跟踪,但即使我发送的电子邮件不存在,日志文件也始终提供 NoError 状态。 现在我正在尝试获取 SentItems 文件夹中的最后一条消息并检查它们的属性,但我找不到该属性的交付状态。我该怎么办? 我的代码现在:
private void checkDeliveryStatuses(ExchangeService service)
{
ItemView itemview = new ItemView(10);
itemview.PropertySet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.InternetMessageId, *some property for status*);
FindItemsResults<Item> newMessages = service.FindItems(WellKnownFolderName.SentItems, itemview);
foreach (Item item in newMessages)
{
EmailMessage msg = item as EmailMessage;
//Somehow get delivery status here
}
}
答案 0 :(得分:2)
传递状态不存储在SentItems文件夹中存储的邮件副本上,因此您尝试执行的操作不会像您尝试使用它一样工作。 EWS有一些消息跟踪操作,您可以尝试使用https://msdn.microsoft.com/en-us/library/office/bb409286(v=exchg.150).aspx#bk_message_tracking,不支持在EWS托管API中使用这些操作,因此如果您想使用它们,则需要使用RAW SOAP或代理对象,例如< / p>
ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.Credentials = new NetworkCredential("username", "password", "domain");
esb.Url = "https://servername/EWS/Exchange.asmx";
esb.RequestServerVersionValue = new RequestServerVersion();
esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
ReplyToItemType riRepItem = new ReplyToItemType();
FindMessageTrackingReportRequestType fmtRequest = new FindMessageTrackingReportRequestType();
fmtRequest.Scope = "Organization";
fmtRequest.StartDateTime = DateTime.Now.AddDays(-4);
fmtRequest.Sender = new EmailAddressType();
fmtRequest.Sender.EmailAddress = "administrator@msgdevelop.com";
fmtRequest.Domain = "msgdevelop.com";
fmtRequest.StartDateTimeSpecified = true;
FindMessageTrackingReportResponseMessageType fmtResponse = esb.FindMessageTrackingReport(fmtRequest);
foreach (FindMessageTrackingSearchResultType fmtSearchResult in fmtResponse.MessageTrackingSearchResults)
{
Console.WriteLine(fmtSearchResult.MessageTrackingReportId);
GetMessageTrackingReportRequestType gmt = new GetMessageTrackingReportRequestType();
gmt.MessageTrackingReportId = fmtSearchResult.MessageTrackingReportId;
gmt.Scope = "Organization";
gmt.ReportTemplate = MessageTrackingReportTemplateType.Summary;
GetMessageTrackingReportResponseMessageType gmtResponse = esb.GetMessageTrackingReport(gmt);
foreach (RecipientTrackingEventType rte in gmtResponse.MessageTrackingReport.RecipientTrackingEvents)
{
Console.WriteLine(rte.EventDescription);
Console.WriteLine(rte.DeliveryStatus);
}
}