Get The Latest Email From EWS

416 Views Asked by At

Can anyone help me, I need to retrieve only the very latest email in my exchange server inbox.

I don't need any other email to show up with the one I want.

But I'm stuck, since the farthest that I could get is only the email I received only today.

I use SearchFilter with DateTimeReceived :

Here's the snipped of my code for the filter :

Dim search As New SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, DateTime.Today.Date)

Thanks in advance.

1

There are 1 best solutions below

6
On BEST ANSWER

Just sort your search results by the DateTimeReceived property, in descending order.

view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

Then when you loop through the results, the first email will be the latest (and then you can jump out of the loop).