We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exchange.ListMessages returns nothing (C#)

Hi,
I’m working with Exchange mail client. While I’m filtering mail by To.Address field it doesn’t work.
Filtering by To.DisplayName - works fine.

In addition, I have the same problem while I’m filtering by From fields but in the opposite:
While I’m filtering mail by From.Address field it works well.
Filtering by From.DisplayName - doesn’t work.

Here below my snippet code:
Creating Query:
MailQuery mq = null;
ExchangeQueryBuilder qb = new ExchangeQueryBuilder();
qb.Or(qb.From.Contains(pFromAddress), qb.From.Contains(pFromName));
qb.To.Contains(pTo);
mq = qb.GetQuery();
return mq;

Create mail client:
NetworkCredential credentials = new NetworkCredential(UserName, Password, Domain);
IEWSClient MailClient = EWSClient.GetEWSClient(ServerHost, credentials);

Get mails by query:
MailClient.ListMessages(pSubfolderUri, pMaxResult, pMailQuery); --> this line returns 0 mails count although there is a mail matched to query.

Note that if I’m testing this code while I’m using IMAP server - I got results.

Additional info:
Working with Aspose.Email version 19.6.0.0
I tried it on IMAP server in office365 - https://outlook.office365.com/EWS/Exchange.asmx
Unfortunately, I can’t attach user & password to tested mail.

Thanks,
Naomi.

@JoGeorge,

I have observed the issue shared by you and request you to please first try using latest Aspose.Email for .NET 19.11 on your end. In case the issue is still reproduced, please share the working sample project reproducing the issue on your end along with test account access.

Hi,
Thanks for your reply.
I tried to test this issue in 19.11 Aspose.Email but it still occurs.

Attached my project (I change version to be 19.6 which is the version we are work with.
AsposeTest.zip (503.7 KB)

Thanks,
Naomi.

@JoGeorge,

I have worked with the sample project shared. An issue with ID EMAILNET-39686 has been created in our issue tracking system to investigate the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hi!
Thank you so much :slight_smile:

@JoGeorge,

You are always welcome :slight_smile:.

Hi, sorry to raise an old complain but i’m experiencing the same problem in 20.5, was this ever fixed?

@eyaldar,

The issue associated in this thread has been marked as resolved in upcoming Aspose.Email for .NET 20.6. We have added a search option by using Advanced Query Syntax (AQS). This feature will solve the issue.

New API members

ExchangeAdvancedSyntaxQueryBuilder class - represents the builder of search expression based on the Advanced Query Syntax (AQS)
ExchangeAdvancedSyntaxMailQuery class - implements an Advanced Query Syntax (AQS) search that is used by EWS.

AQS described at https://docs.microsoft.com/exchange/client-developer/exchange-web-services/how-to-perform-an-aqs-search-by-using-ews-in-exchange.

Code examples

Create a search query using query builder builder:

using (IEWSClient client = EWSClient.GetEWSClient(exchangeMailboxUri, name, password))
{
    ExchangeAdvancedSyntaxQueryBuilder advancedBuilder = new ExchangeAdvancedSyntaxQueryBuilder();
    advancedBuilder.To.Contains("jim.martin@test.com");
    advancedBuilder.From.Contains("Lindsey Smart");
    //advancedBuilder.To.Contains("Jim Martin");
    //advancedBuilder.From.Contains("lindsey.smart@test.com");

    ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, advancedBuilder.GetQuery());
}

Сreate the search query directly by using Advanced Query Syntax (AQS):
See the AQS description at https://docs.microsoft.com/exchange/client-developer/exchange-web-services/how-to-perform-an-aqs-search-by-using-ews-in-exchange.

using (IEWSClient client = EWSClient.GetEWSClient(exchangeMailboxUri, name, password))
{
    ExchangeAdvancedSyntaxMailQuery query = new ExchangeAdvancedSyntaxMailQuery("(to:jim.martin@test.com) AND (from:lindsey.smart@test.com)");
    ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query);
}
1 Like

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