none
Converting a Recipient to a MailItem.To/CC/BCC RRS feed

  • Question

  • For my code, I need to spin through all the recipients of an email (To, CC and BCC) and get their respected emails and compare the email domains against a white/black list.

    If an email is on the black list, I have a pop-up window that will be presented to the user to have them validate that these email address are correct. 

    The challenge is that I can am using the  mailItem.Recipients enumeration, to build a list of email address. The problem I have is that I need to know which emails came from the To/CC/BCC lines so when a user removes and email address from the pop-up I can reload the To/CC/BCC. 

    I know that the MailItem.TO/CC/BCC object returns a string of all the names in each, is there a way to convert a MailItem.To/CC/BCC to a Recipient object? 

    Thanks


    Thursday, July 9, 2015 2:18 PM

Answers

  • That answer was SPOT ON.

    Thanks again Eugene, and everyone else for their support.

    --

     foreach (Outlook.Recipient receipient in mailItem.Recipients)
     {
                    int receipientType = receipient.Type;

     }

    • Marked as answer by L.HlModerator Saturday, July 18, 2015 9:50 AM
    Thursday, July 9, 2015 6:01 PM

All replies

  • Why do you need To/CC/BCC? Recipient object already exposes the Type property (olTo / olCC / olBCC).

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, July 9, 2015 2:28 PM
  • Hi David,

    The Namespace class provides the CreateRecipient method which creates a Recipient object.

    Sub ResolveName()  
     Dim myNamespace As Outlook.NameSpace  
     Dim myRecipient As Outlook.Recipient  
     Dim CalendarFolder As Outlook.Folder 
     Set myNamespace = Application.GetNamespace("MAPI")  
     Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev")
     myRecipient.Resolve  
     If myRecipient.Resolved Then  
      MsgBox myRecipient.Address 
     End If  
    End Sub 

    Note, you can use the Recipients property of the MailItem class which returns a Recipients collection that represents all the recipients for the Outlook item. The Type property of the Recipient class returns an integer representing the type of recipient.

    Depending on the type of recipient, this property returns or sets a integer corresponding to the numeric equivalent of one of the following constants:

    Thursday, July 9, 2015 3:04 PM
  • That answer was SPOT ON.

    Thanks again Eugene, and everyone else for their support.

    --

     foreach (Outlook.Recipient receipient in mailItem.Recipients)
     {
                    int receipientType = receipient.Type;

     }

    • Marked as answer by L.HlModerator Saturday, July 18, 2015 9:50 AM
    Thursday, July 9, 2015 6:01 PM