How to read emails on first come and first serve basis

Hi,

We are using Aspose for reading email from inbox but the problem is that it's reading mail from inbox which is newer and I need it to read on the first come first serve basis.


This message was posted using Email2Forum by Imran Rafique. (private)

Hi,

Thank you for writing to Aspose Support team.

Can you please share with us which email you are using? i.e. ImapClient, Pop3Client or Exchange? This is the default behavior of all these API’s communication clients. However, both the ImapClient and IEWSClient provides support for retrieving messages by specifying some filter or list messages with paging support.

Using MailQuery, you can retrieve those messages only that meet the defined criterea. For example, you can list messages from yesterday only and then parse through these using your own logic. Similarly, you can retrieve messages for today and then parse them in reverse order using your own logic.

The Paging support in IMAPand EWS Client of the API allows you to specify number of messages to be specified per page. This way, you can list messages from the server with defined page size and then access the desired page for retrieved messages.

The EWS Client API also provides a combination of MailQuery and Paging support that may be helpful to you. Please go through the following documentation articles for further information in this regard and let us know if you need further assistance.

it’s outlook mail with exchange server.


msgCollection = client.ListMessages(client.GetMailboxInfo().InboxUri, pMaxNoOfEmailsToGet);

Its giving email Newer first. but i want older email first.

Hi,

I would suggest you to use the ExchangeQueryBuilder and retrieve the messages on date base. For example, you may always check for today emails and list the messages from the inbox using the query builder. Once the list of emails is retrieved, you can parse the list in reverse order to get to older messages first. Please try the following code sample for your requirements and share your feedback with us.

Sample Code:

IEWSClient client = GetAsposeEWSClient1(); //some test Exchange account

ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.InternalDate.On(DateTime.Today);

ExchangeMessageInfoCollection msgsColl = client.ListMessages(client.MailboxInfo.InboxUri, builder.GetQuery());
Console.WriteLine("Total Messaegs Count: " + msgsColl.Count);

for (int i = msgsColl.Count-1; i > 0; i–)
Console.WriteLine(msgsColl[i].Subject);

I have Tried


ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.InternalDate.On(DateTime.Today);

ExchangeMessageInfoCollection msgsColl = client.ListMessages(client.MailboxInfo.InboxUri, builder.GetQuery());


but it’s showing msgcoll=0 but we have 10 emails in inbox.

Hi,

This works well at our end. Can you please change the check on InternalDate to SentDate and share your feedback with us? If the issue still persists, please share a sample test account details with us where we can try the same and investigate the issue further.

Sample Code:

builder.SentDate.On(DateTime.Today);

ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.InternalDate.Since(DateTime.Now.AddDays(-3));
ExchangeMessageInfoCollection msgsColl = client.ListMessages(client.MailboxInfo.InboxUri, builder.GetQuery());

This is fetching all mail from last 3 days.

But now i want to take 10 mail at once from last 3 days mail and process it.(older mail first) with pMaxNoOfEmailsToGet in below code:

msgCollection = client.ListMessages(client.GetMailboxInfo().InboxUri, pMaxNoOfEmailsToGet, builder.GetQuery(),false);

Hi,


You may please use paging mechanism to extract messages form the exchange server under heading “Enumerating messages with paging in EWS” in the article here.

As there is no built in mechanism to retrieve sorted messages, you may use some programming technique to sort ExchangeMessageInfoCollection and then retrieve the messages with the sorted info list.

The issues you have found earlier (filed as EMAILNET-35128) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.