+1 vote

We keep receiving below error randomly on few emails.
Unable to cast object of type "Limilabs.Mail.Headers.MailGroup" to type "Limilabs.Mail.Headers.MailBox"

Can you please let us know how this can be resolved ?


1 Answer

0 votes
Best answer

This is not a download error.

In your code you must be casting object of type MailAddress to MailBox explicitly.

MailAddress can be MailBox -or- MailGroup (both inherit from MailAddress).

Please use GetMailboxes method:

var mailboxes = email.To.SelectMany(address => address.GetMailboxes())


handle mailboxes and groups differently.

You can find more on this here:

by (291k points)