Getting To, Cc and BCc email addresses from a MailItem in Outlook

Seems to be a simple task. Right? But, not exactly.

Say olMailItem is the object of Outlook.MailItem. From olMailItem.TO, olMailItem.CC and olMailItem.BCC, we get the names of the recipients from the Outlook contacts. But not their email addresses.

To get email addresses, we can use the following code.

Dim olRecipients As Outlook.Recipients

olRecipients = olMailItem.Recipients

Dim strToEmails, strCcEmails, strBCcEmails As String

For Each olRecipient As Outlook.Recipient In olRecipients

If olRecipient.Type = Outlook.OlMailRecipientType.olTo Then

strToEmails += olRecipient.Address & vbCrLf

ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olCC Then

strCcEmails += olRecipient.Address & vbCrLf

ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olBCC Then

strBCcEmails += olRecipient.Address & vbCrLf

End If

Next

MessageBox.Show(“To: ” & strToEmails & “Cc: ” & strCcEmails & “BCc: ” & strBCcEmails)

Hope this helps!

Advertisements
This entry was posted in Outlook and tagged , by Pranav. Bookmark the permalink.

About Pranav

A Software Engineer by profession and a Geek at heart. I love exploring new technologies and working on algorithmic problems. As of now, I write code for bread, butter and satisfaction. I like to develop applications, and generally that involves much more than writing code. It’s not just about hurling code, but producing something meaningful that has a measurable and positive impact, helps others and solves interesting problems.

3 thoughts on “Getting To, Cc and BCc email addresses from a MailItem in Outlook

  1. Hello,
    Could you please help me.
    I am trying to use vb script to edit outlook in order to meet my requirement.
    my requirement:
    1. before sending an email, user must get a prompt if they want to send this email or not.
    2. in the prompt or message box above, i must also display the recipients email address.

    the first part is working fine, but i am really stuck with the second part i.e. in the message box I must include the email addresses in the CC and BCc field.

    your help will be much appreciated.

    thank you.

    • Hi Roy,
      VB Script?
      Assuming you are using VB.NET. Is the above code not working for you?
      What is the account type of the email that is configured in Outlook? Is that POP3 or Exchange?
      If it is exchange, you need to use another method to extract the recipients from email.
      I wrote a blog post on how to get recipients from exchange account also. You can find it in this blog.

      Hope this helps! Let me know, if you have any queries.

      • Hi Pranav,

        Thanks a lot for getting back to me.

        Well I am using imap in Outlook 2007.
        Actually, I have already added the lines below which prompts the user whether to send the email or not.
        the lines are:

        Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim intRes As Integer
        Dim strMsg As String
        strMsg = “Do you really wantt o send this message now?”
        intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton1, “Confirm Send “)
        If intRes = vbNo Then
        Cancel = True
        End If

        End Sub

        As i mentioned this part is working.

        The last final bit is to add the recipient email address in the message box so that the user can easily see their addressed recipients i.e the email addresses in the cc and bcc fields.

        please friend, your help will be much appreciated.

        thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s