2017-07-17 81 views
0

我需要使用Exchange Web服務API發送郵件,然後檢查郵件是否已發送。爲此,我嘗試使用EWS跟蹤,但即使發送的電子郵件不存在,日誌文件也會始終給出的NoError狀態。 現在我試圖在SentItems文件夾中查看最後的消息並檢查它們的屬性,但我無法找到傳遞狀態的屬性。我能用它做什麼? 我現在代碼:獲取郵件傳遞狀態EWS

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 
     } 
    } 

回答

2

交貨狀態不存儲在存儲在SentItems文件夾中的郵件的副本,你的努力做到不工作,你要使用它的方式。 EWS有一些郵件跟蹤操作,你可以嘗試使用https://msdn.microsoft.com/en-us/library/office/bb409286(v=exchg.150).aspx#bk_message_tracking有那麼如果你想使用它們,你要麼需要使用RAW SOAP或代理對象,例如

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 = "[email protected]"; 
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); 
} 
} 
的EWS託管API使用這些操作不支持
+0

非常感謝,但我如何獲得ExchangeServiceBinding對象?現在我有命名空間錯誤。我試圖谷歌它,但沒有幫助。 –

+0

您需要生成Web服務代理對象,例如在Visual Studio中https://msdn.microsoft.com/zh-cn/library/office/bb408520(v=exchg.140).aspx(與2010年的2010版相同,2015年和2017年) –

+0

再次問候。我得到「訪問被拒絕,請檢查憑據並重試。」在fmtResponse。憑據是正確的。什麼可能是錯的? –