Free Support Forum -

Retrieving undelivered emails using Imapclient


I cant find any option in ImapQueryBuilder class similar to ExchangeQueryBuilder to retriev only those emails that are unable to deliver. In EWS, I can do this by builder.ContentClass.Equals(“REPORT.IPM.Note.NDR”);

but I don’t find any such option using ImapQueryBuilder. Can you guide how to achieve this using Iampclient?


Hi Mark,

Please refer to the following code sample for retrieving undelivered emails using ImapClient. It doesn’t use any filtering based on ContentClass, as it is not supported by ImapQueryBuilder, and applies the filter based on subject containing the word “Undelivered”. You can use this method as a workaround until we identify if it’s possible to provide filtering based on ContentClass as in EWS.

ImapClient client = new ImapClient(“server address”, 993, “username”, “password”);

client.EnableSsl = true;




ImapQueryBuilder builder = new ImapQueryBuilder();


MailQuery query = builder.GetQuery();

ImapMessageInfoCollection messages = client.ListMessages(query);

foreach (ImapMessageInfo msgInfo in messages)
Console.WriteLine(“Subject:” + msgInfo.Subject);

I hope this will suffice for your needs.