Getting the SMTP Email Address of exchange cc recipient vb.net

printmedia
printmedia used Ask the Experts™
on
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()
 mi.SaveAs("c:\temp\test.msg")
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))
 Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
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 = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

        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

        Next

        Return ccString
    End Function

Open in new window


Regards,
Chinmay.

Author

Commented:
That did it. Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial