.net - Get ItemId of next email given ItemId of current email, using Exchange Web Services (EWS) Managed API -
To read an email from mailbox, write a method in the C # that uses the Exchange Web Services (EWS) managed API The requirement is given to itemId / UniqueId of the current e-mail, returns the itemId / UniqueId to the next email in the inbox after the existing email.
Besides, for various reasons, I need to become a static stateless method, i.e., it can not rely on any member / global variable which continues through the call. In this way I can not only store a reference for an example of FindItemsResults object and every time the method is called, then go to the next item.
I tried to apply the method using the following code (only simple examples, no error checking):
Microsoft. Exchange. Using web services; Using Microsoft.Exchange.WebServices.Data; ... ... public string GetNextEmailId (string currentItmid) {// Set Up Exchange Web Service Connection Exchange Service Service = New ExchangeService (ExchangeVersion.Exchange2007_SP1); Service.AutodiscoverUrl ("example.user@contoso.com"); // Create a search filter to find the next email after an existing email itemId itemId = new item ID (current ITMID); Searchfilter sfNextEmail = New SearchFilter.isGRTRAN (e-mailmessage Cichemada, ID, Item ID); // Find the next email in the Inbox Item View Item View = New Item View (1); ItemView.OrderBy.Add (EmailMessageSchema.DateTimeReceived, SortDirection.Ascending); FindItemsResults & LT; Item & gt; Address: Response = Service.Fund Items (WellenFolderName Inbox, SFNEEEEEF, ITum); // Return the return of the unique ID of the next email return. [1] IED Unique Id; }
But when I run this method, throws the following exceptions from the service. FindItems Row:
System.ArgumentException: "Validation Failed. Parameter Name: searchFilter"
Internal Exception - Microsoft.Exchange.WebServices.Data.ServiceValidationException: "Type 'ItemId' in Value Search Filter Comparable values can not be the same. "
An option is to use all the passquetts to find all emails in the inbox, and through these, check the IID before going to find the current email, then go to the next one and return your unique ID. But I think it is likely to be slow and temporary. I hope that there is a better way of achieving this.
Any help or suggestions would be greatly appreciated. I can not find any solutions to search the web.
If you are the current email you can tie it to:
EmailsMessage = Email message.bund (service, id);
Then you have the date of receiving the existing email - create a search filter for all the dates that are more than that date and you already use your order through the code.
Comments
Post a Comment