none
createrecipient gets wrong recipient RRS feed

  • Question

  • I have an excel macro to open a user's mailbox and get the tasks.
    I have discovered the createrecipient method finds a recipient in my "contacts" folder and does not look at the server's UserList.  Because of this, it gets an incorrect recipient some of the time.

    Our AD has 2 users:
      user = fred
        Full Name = Fred Flintstone
     Email = fred@bedrock.com
      user = wilma
        Full Name = Wilma Flintstone
     Email = wilma@bedrock.com

    My Contacts folder has an entry to email to both people:
      Display Name = Fred n Wilma Flintstone
     Full Name = Fred n Wilma Flintstone
     Email = frednwilma@bedrock.com

    When my macro runs, it get the object for Fred Flintstone on PC A and for Fred and Wilma Flintstone on PC B.

    My code is this:
     Dim objApp As Outlook.Application
     Dim objNS As Namespace
     Dim objRcpt As Recipient

     Set objApp = CreateObject("Outlook.Application")
     Set objNS = objApp.GetNamespace("MAPI")
     Set objRcpt = objNS.CreateRecipient(User_Name)

    On PC A:
     objRcpt = "Fred Flintstone"
      Address = "/o=CARTGOLF/ou=first administrative group/cn=Recipients/cn=fred"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred Flintstone"
      
    On PC B:
     objRcpt = "Fred Flintstone"
      Address = "frednwilma@bedrock.com"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred n Wilma Flintstone"

    Why does it get the incorrect entry?
    Is there any way to control the createrecipient method to only look at "Users" and not "Contact Entries"?
    Is there any way to get the createrecipient method to match against the complete entry and not substrings of words?
    Is there a different method I should be using?

    My goal is I wnat this macro to only look at User Mailboxes on the exchange server, not any entry in my "Contacts" folder.

    Thanks,
    Mike

     

    Friday, January 28, 2011 5:20 AM

Answers

  • That's typical of Exchange recipient resolution if there aren't distinct and unique names. Try using the actual SMTP address equivalents for the desired recipients instead of using a name. That will work.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mcfip_home" <=?utf-8?B?bWNmaXBfaG9tZQ==?=> wrote in message news:61670e2d-33f9-4c6e-a309-dbdf5d6123d0...

    I have an excel macro to open a user's mailbox and get the tasks.
    I have discovered the createrecipient method finds a recipient in my "contacts" folder and does not look at the server's UserList.  Because of this, it gets an incorrect recipient some of the time.

    Our AD has 2 users:
      user = fred
        Full Name = Fred Flintstone
     Email = fred@bedrock.com
      user = wilma
        Full Name = Wilma Flintstone
     Email = wilma@bedrock.com

    My Contacts folder has an entry to email to both people:
      Display Name = Fred n Wilma Flintstone
     Full Name = Fred n Wilma Flintstone
     Email = frednwilma@bedrock.com

    When my macro runs, it get the object for Fred Flintstone on PC A and for Fred and Wilma Flintstone on PC B.

    My code is this:
     Dim objApp As Outlook.Application
     Dim objNS As Namespace
     Dim objRcpt As Recipient

     Set objApp = CreateObject("Outlook.Application")
     Set objNS = objApp.GetNamespace("MAPI")
     Set objRcpt = objNS.CreateRecipient(User_Name)

    On PC A:
     objRcpt = "Fred Flintstone"
      Address = "/o=CARTGOLF/ou=first administrative group/cn=Recipients/cn=fred"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred Flintstone"
      
    On PC B:
     objRcpt = "Fred Flintstone"
      Address = "frednwilma@bedrock.com"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred n Wilma Flintstone"

    Why does it get the incorrect entry?
    Is there any way to control the createrecipient method to only look at "Users" and not "Contact Entries"?
    Is there any way to get the createrecipient method to match against the complete entry and not substrings of words?
    Is there a different method I should be using?

    My goal is I wnat this macro to only look at User Mailboxes on the exchange server, not any entry in my "Contacts" folder.

    Thanks,
    Mike

     


    Ken Slovak MVP - Outlook
    Friday, January 28, 2011 3:13 PM
    Moderator
  • On the MAPI level, one can perform a PR_ANR restriction on any address list - PR_ANR support is required by MAPI if the address book provider supports name resolution.

    <plug>

    Redemption exposes this functionality through the RDOAddressList.ResolveName/ResolveNameEx methods - http://www.dimastr.com/redemption/rdo/rdoaddresslist.htm - a call to RDOSession.AddressBook.GAL.ResolveName() would resolve a given name against GAL only.

    </plug>

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, January 31, 2011 5:04 PM

All replies

  • That's typical of Exchange recipient resolution if there aren't distinct and unique names. Try using the actual SMTP address equivalents for the desired recipients instead of using a name. That will work.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mcfip_home" <=?utf-8?B?bWNmaXBfaG9tZQ==?=> wrote in message news:61670e2d-33f9-4c6e-a309-dbdf5d6123d0...

    I have an excel macro to open a user's mailbox and get the tasks.
    I have discovered the createrecipient method finds a recipient in my "contacts" folder and does not look at the server's UserList.  Because of this, it gets an incorrect recipient some of the time.

    Our AD has 2 users:
      user = fred
        Full Name = Fred Flintstone
     Email = fred@bedrock.com
      user = wilma
        Full Name = Wilma Flintstone
     Email = wilma@bedrock.com

    My Contacts folder has an entry to email to both people:
      Display Name = Fred n Wilma Flintstone
     Full Name = Fred n Wilma Flintstone
     Email = frednwilma@bedrock.com

    When my macro runs, it get the object for Fred Flintstone on PC A and for Fred and Wilma Flintstone on PC B.

    My code is this:
     Dim objApp As Outlook.Application
     Dim objNS As Namespace
     Dim objRcpt As Recipient

     Set objApp = CreateObject("Outlook.Application")
     Set objNS = objApp.GetNamespace("MAPI")
     Set objRcpt = objNS.CreateRecipient(User_Name)

    On PC A:
     objRcpt = "Fred Flintstone"
      Address = "/o=CARTGOLF/ou=first administrative group/cn=Recipients/cn=fred"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred Flintstone"
      
    On PC B:
     objRcpt = "Fred Flintstone"
      Address = "frednwilma@bedrock.com"
      Class = olRecipient
      Display/Type = olUser
      Name = "Fred n Wilma Flintstone"

    Why does it get the incorrect entry?
    Is there any way to control the createrecipient method to only look at "Users" and not "Contact Entries"?
    Is there any way to get the createrecipient method to match against the complete entry and not substrings of words?
    Is there a different method I should be using?

    My goal is I wnat this macro to only look at User Mailboxes on the exchange server, not any entry in my "Contacts" folder.

    Thanks,
    Mike

     


    Ken Slovak MVP - Outlook
    Friday, January 28, 2011 3:13 PM
    Moderator
  • On the MAPI level, one can perform a PR_ANR restriction on any address list - PR_ANR support is required by MAPI if the address book provider supports name resolution.

    <plug>

    Redemption exposes this functionality through the RDOAddressList.ResolveName/ResolveNameEx methods - http://www.dimastr.com/redemption/rdo/rdoaddresslist.htm - a call to RDOSession.AddressBook.GAL.ResolveName() would resolve a given name against GAL only.

    </plug>

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, January 31, 2011 5:04 PM