Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Outlook - Resolve TO/CC/BCC email addresses

162 views
Skip to first unread message

Serge Bollaerts

unread,
Jul 3, 2010, 7:04:59 PM7/3/10
to
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

Ken Slovak

unread,
Jul 6, 2010, 9:44:48 AM7/6/10
to
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[i];
string addy = recip.Address;

recip = null;
}
}

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Serge Bollaerts" <sboll...@hotmail.com> wrote in message
news:C7093FBC-76A4-4963...@microsoft.com...

0 new messages