none
How to get the DisplayName from IMsoContactCard context? RRS feed

  • Question

  • Anyone know how to get the Display name from a IMsoContactCard of type msoContactCardAddressTypeSMTP?  The Contact Card is the new fancy popup that shows when you hover over a MailItem sender or recipient in Outlook 2010.  All the samples use the very robust msoContactCardAddressTypeOutlook. In my inbox, most MailItem Senders/Recipients are simple SMTP addresses.  With a ContactCard of type msoContactCardAddressTypeOutlook, I can get the AddressEntry and get everything I need.  Can you get an AddressEntry for msoContactCardAddressTypeSMTP?  If not is there some other way to get the display name?  A typical SMTP recipient looks like this:  FirstName LastName <firstname@domain.com> .   The text prior to the < is the display name. Sorry to be so obvious.  Any help is much appreciated.

    -- outlook noob

    Friday, May 4, 2012 12:52 AM

Answers

  • Isn't that bizarre... I can only think of using Application.ActiveExplorer.Selection.Item(1) to retrieve the currently selected item, then looping through its Recipients colleciton to find the matching Recipient (based on Recipient.Address), then reading Recipient.Name property.

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

    Tuesday, May 8, 2012 12:46 AM

All replies

  • I am not sure I understand the problem - wouldn't Recipient.Name work for you?

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

    Friday, May 4, 2012 5:27 AM
  • I should have given more of an explanation.  Sorry. I'm working on a VSTO Outlook 2010 add-in. I've modified the context menu that appears when you right-click a single recipient or sender in a MailItem. When you right-click, a context menu appears.  This is the ContextMenuContactCardRecipient context menu.  Clicking any item on this menu provides the Control.Context of type IMsoContactCard.  Is there a way that I can convert that to a recipient or sender as the case may be?
    • Edited by Spencer Williamson Friday, May 4, 2012 7:47 PM added dev environment for clarity
    Friday, May 4, 2012 6:14 PM
  • Hmmm.... I have never tried that before - what do you get for the ContactCard.Parent object?

    Alos, looking at http://msdn.microsoft.com/en-us/library/ee909466.aspx, it appears that the Address property contains the entry id of the address entry object. You should be able to open it using Namespace.GetAddressEntryFromID. Once you have the AddressEntry object, you can use the Type, Address and Name properties.


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

    Friday, May 4, 2012 11:18 PM
  • Dmitry,  

    Sadly, ContactCard.Parent = null.  The link you listed isn't working for me.  It takes me to a "Content not found" page.  The GetAddressEntryFromID works great if the ContactCard.AddressType == msoContactCardAddressTypeOutlook.  For example:

    if (card.AddressType == Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook) {
    	Outlook.AddressEntry ae = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address);
    	if (ae != null) {
    		// do something here
    	}
    }

    However,  it fails miserably if the AddressType is msoContactCardAddressTypeSMTP.  Thanks for taking time to look at this!

    Here's my generated exception:

    An Error has occurred in SolCom2010
    Message: Could not complete the operation. One or more parameter values are not valid.
    File: RibbonAddin
    Location: OnAddToSolomonClick
    Version: 1.0.0.0
    User: spencerw
    Host: MeanMachine
    Source: Microsoft Outlook
    Method: GetAddressEntryFromID
    Module: C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll
    Assembly: Microsoft.Office.Interop.Outlook, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c

    System.Runtime.InteropServices.COMException (0x80020009): Could not complete the operation. One or more parameter values are not valid.
       at Microsoft.Office.Interop.Outlook.NameSpaceClass.GetAddressEntryFromID(String ID)
       at SolCom2010.RibbonAddin.OnAddToSolomonClick(IRibbonControl control) in C:\Dev\exodus\SolCom2010\SolCom2010\RibbonAddin.cs:line 132
    Friday, May 4, 2012 11:45 PM
  • What is the value of the Address property?

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

    Sunday, May 6, 2012 5:06 PM
  • It is simply the email address  email@domain.com.
    Monday, May 7, 2012 9:08 PM
  • But when GetAddressEntryFromID works, is it a hex string?


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

    Monday, May 7, 2012 9:15 PM
  • Yes it is for address types msoContactCardAddressTypeOutlook. 
    Monday, May 7, 2012 11:46 PM
  • Isn't that bizarre... I can only think of using Application.ActiveExplorer.Selection.Item(1) to retrieve the currently selected item, then looping through its Recipients colleciton to find the matching Recipient (based on Recipient.Address), then reading Recipient.Name property.

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

    Tuesday, May 8, 2012 12:46 AM