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

Free Support Forum - aspose.com

Filter in attachment


I wanted to search in attachment like name, body or extension.

Is there any function or class by which i will search in attachment because i already tried MailQueryBuilder in which there is no method for attachment.


Could you please elaborate your requirements a little more? Please give us an example for what you want to achieve using the API. If you have some sample message file for reference, please share that with us as well.


I wanted to filter mails according to the attachment fields.

Like when i am using MAPI function for filter it gives option to search for mails having attachment name “Sample.txt” or mails having attachment extension “.pdf” or mails having attachment size greater than 10KB.
Here is the sample code in MAPI

For Extension
IRestrictionSub Restr =resor.Add(RES_SUBRESTRICTION);

RestrAtt =Restr.SetKind(RES_CONTENT);

for attchment name

for attachment size

By this we can filter mail according to the attachment name, extension and size but there is not such kind of option in your API.
Check this link for more : http://www.dimastr.com/redemption/mapitable.htm

Also, filter in body of a mail is not working properly. Every time i apply filter on body it gives result 0.
Here is the sample code i used in my code

ExchangeQueryBuilder exchQuery = new ExchangeQueryBuilder();
MailQuery queryBody = null;
queryBody = exchQuery.GetQuery();
ExchangeMessageInfoCollection exchMsgInfoCol = exchClientBase.ListMessages(exchClientBase.MailboxInfo.RootUri, queryBody);

My another query is,
GetMailboxSize() is not working properly. It gives us wrong size of mailbox.

IEWSClient exchClientBase;
ExchangeMailboxInfo exchMailboxInfo = exchClientBase.GetMailboxInfo();
long iMailboxSize = exchClientBase.GetMailboxSize();


The follwoing code sample seems to be what you want w.r.t Attachment file name, extension or size. However, we couldn’t find a working version of it. We’re looking into it and will update you with our findings once we are able to figure out the issue.

IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", "UserTwo@Aspose2018.onmicrosoft.com", "Aspose1234");

var queryBuilder = new ExchangeQueryBuilder();
queryBuilder.ExtendedProperties[KnownPropertyList.AttachExtension].AsString.Contains("jpg", true);
var query = queryBuilder.GetQuery();
string[] uriList = client.ListItems(client.MailboxInfo.InboxUri, query);

For your queries related to searching by message body, please change this line of code:

exchClientBase.ListMessages(exchClientBase.MailboxInfo.RootUri, queryBody);


exchClientBase.ListMessages(exchClientBase.MailboxInfo.InboxUri, queryBody);

The GetMailboxSize() is working fine with the above shared account and you can test it at your end as well.

3 posts were split to a new topic: Issues while taking backup of folders from account on exchange


Any update on applying filter in attachment?


We won’t be able to provide such functionality as the same is not available in the EWS itself.