Outlook - Resolve TO/CC/BCC email addresses

  • Thread starter Serge Bollaerts
  • Start date

S

Serge Bollaerts

Hello,

Before I kill a chicken to get a mystic answer (after having read "Voodoo
for Dummies"), I'm turning to the community to get some light on my problem.

I'm developping an Outlook add-in in C# 2.0 and I'm trying to get the email
addresses in the TO, CC and BCC fields through a MailItem object passed in
the Outlook.Application.ItemSent event.
when querying the properties To, CC, and BCC, I noticed that these fields
retrieved the friendly names instead of the email addresses. Since the
Outlook address book does not contain any entry, I cannot figure out how
Outlook maps that friendly name to a real email address.

After spending hours on Internet, I found a method similar to:
private string GetEmailAddressForExchangeServer(string emailName)
{
string rc;
Outlook.MailItem msg;
Outlook.Recipient recipient;

msg =
(Outlook.MailItem)_application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
recipient = msg.Recipients.Add(emailName);

recipient.Resolve();

rc = recipient.Address; --> Return null
return rc;
}

Should I mention that it does not work?

I've read a lot of (old) documentation talking about that well-known CDO.
But since .Net, I don't know how to get it (yeah, ok: reference the CDO COM
object): All samples told about MAPI.Session which is no in the standard
library (on a Windows 7, I found CDO for Windows 2000)

My dev environment is Outlook 2007 standalone (not linked to an Exchange
Server), VS 2010 (project based on Framework.NET 2.0)

Your help is really welcome! (And the chicken will bless you!)
Serge
 
Ad

Advertisements

K

Ken Slovak

If a friendly name is resolvable to an email address, the name must be
either from a contact or entry in the Exchange global address list, or it
would be in the nickname cache. Otherwise Outlook wouldn't be able to
resolve a name to an address.

You should be able to just iterate the Recipients collection and pick up the
addresses that way:

Outlook.MailItem mail = Item As Outlook.Mailitem;
Outlook.Recipients recips = mail.Recipients;
Outlook.Recipient recip = null;
int Count = recips.Count;
if (Count > 0)
{
for (int i = 1; i <= Count; i++)
{
recip = recips;
string addy = recip.Address;

recip = null;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top