Getting the SMTP Email Address of exchange cc recipient

Hi all.

I'm trying to get the email address of my cc recipients but when I use the following code what I get is the display name that is in my address book and not the actual email address (in the MsgBox(String.Format("CC:{0}", item.CC)) line of code). Any idea how I can get this? Thank you in advance.

 Dim OL As Outlook.Application = CreateObject("Outlook.Application")

Dim mi As Microsoft.Office.Interop.Outlook.MailItem

 For Each mi In OL.ActiveExplorer.Selection()
Dim item As Outlook.MailItem = CType(OL.CreateItemFromTemplate("c:\temp\test.msg", Type.Missing), Outlook.MailItem)
MsgBox(String.Format("Subject:{0}", item.Subject))
MsgBox(String.Format("SenderName:{0}", item.SenderName))
 MsgBox(String.Format("CC:{0}", item.CC))
  MsgBox(String.Format("Text Body:{0}", item.Body))

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi printmedia,

Use the code below to get CC mail Ids. You would want to format it a bit as I have included name + email address in a single string.
You could return a list of string as well by modifying ccString += (recipient.Name & " = " & accessor.GetProperty(PR_SMTP_ADDRESS))

Function GetCCString(mail As Outlook.MailItem)
        Dim ccString As String = String.Empty

        Const PR_SMTP_ADDRESS As String = ""

        Dim recipients As Outlook.Recipients
        Dim recipient As Outlook.Recipient
        Dim accessor As Outlook.PropertyAccessor

        recipients = mail.Recipients
        For Each recipient In recipients
            accessor = recipient.PropertyAccessor
            If (mail.CC.Contains(recipient.Name)) Then
                ccString += (recipient.Name & " = " & accessor.GetProperty(PR_SMTP_ADDRESS))
            End If


        Return ccString
    End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
printmediaAuthor Commented:
That did it. Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.