In Mail.dll email library IMail.To
, IMail.Cc
, IMail.Bcc
and IMail.ReplyTo
properties are of IList<MailAddress>
type.
The reason for this, is to handle not only regular mailboxes, but also email address groups.
In those collections you can find two kinds of objects:
MailBox
– which represents single mailbox (e.g. "John" <john@example.com>
)
MailGroup
– which represents group of email
addresses (e.g. HR: <pat@example.com>, "John" <john@example.com>;
)
To list MailBoxes only, use OfType<>
method:
using(Pop3 pop3 = new Pop3())
{
pop3.ConnectSSL("pop3.server.com");
pop3.UseBestLogin("user", "password");
List<string> uids = pop3.GetAll();
foreach (string uid in uids)
{
IMail email = new MailBuilder()
.CreateFromEml(pop3.GetMessageByUID(uid));
foreach (MailBox mailbox in email.To.OfType<MailBox>())
{
string name = mailbox.Name;
string address = mailbox.Address;
}
}
pop3.Close();
}
You can find more details here:
https://www.limilabs.com/blog/how-to-access-to-cc-bcc-fields