Reputation: 97
I have written this excerpt of code to grab the email addresses of users from the to, cc and bcc lines when the email send button is clicked.
if (Item is Outlook.MailItem)
{
Outlook.MailItem mailItem = Item as Outlook.MailItem;
Outlook.Recipients myRecipients = mailItem.Recipients;
foreach (Outlook.Recipient recipient in myRecipients)
{
addresses.Add(recipient.Address);
}
}
The code does what I need it to do. However, if the user enters a distribution list in the to, cc or bcc lines my program is not able to read the email addresses from the distribution list. I am looking for a solution to either read email addresses from the distribution list or expand the distribution list.
Upvotes: 0
Views: 2039
Reputation: 33381
You can call ResolveAll()
method of Recipients
or Resovle()
for each Recipient
.
After resolving all addresses get ExchangeDistributionList
object via GetExchangeDistributionList()
which provides the method GetMemberOfList()
which it its turn returns AddressEntries
object.
Upvotes: 1