none
Outlook Add-in: Fetch attendees email address of selected meeting

    Question

  • I am developing a small Outlook add-in which will fetch all information about selected meeting and push this information to our in-house portal. Implementation is complete except RequiredAttendees part. Not sure why, but Interop.Outlook.AppointmentItem object is only returning full names (as string) of the attendees. I am more interested in their email address of attendees. Here is my code snippet to replicate the issue:

    try
    {
        AppointmentItem appointment = null;
        for (int i = 1; i < Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count + 1; i++)
        {
            Object currentSelected = Globals.ThisAddIn.Application.ActiveExplorer().Selection[i];
            if (currentSelected is AppointmentItem)
            {
                appointment = currentSelected as AppointmentItem;
            }
        }
    
        // I am only getting attendees full name here
        string requiredAttendees = appointment.RequiredAttendees;
    
    }
    catch (System.Exception ex)
    {
        LogException(ex);
    }

    I can see RequiredAttendees property is defined as string in Microsoft.Office.Interop.Outlook._AppointmentItem interface.

    //
    // Summary:
    //     Returns a semicolon-delimited String (string in C#) of required attendee
    //     names for the meeting appointment. Read/write.
    [DispId(3588)]
    string RequiredAttendees { get; set; }

    I will greatly appreciate if someone can help me to resolve this issue or provide some around to get attendees email addresses.

    Thanks.

    Thursday, January 10, 2013 4:13 PM

Answers

  • Use the AppointmentItem.Recipients collection. Look for Recipient.Type == olTo

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

    • Marked as answer by Firoz A Thursday, January 10, 2013 6:17 PM
    Thursday, January 10, 2013 5:33 PM
  • The PR_SMTP_ADDRESS_A property is not guaranteed to be present in the recipient table.

    Use Recipient.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3002001F") to retrieve the PR_ADDRTYPE property. If it is "EX", use Recipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress. Be prepared to handle errors if any of the properiers returns null or raises an error.


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

    • Marked as answer by Firoz A Thursday, January 10, 2013 6:29 PM
    Thursday, January 10, 2013 6:22 PM

All replies

  • Use the AppointmentItem.Recipients collection. Look for Recipient.Type == olTo

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

    • Marked as answer by Firoz A Thursday, January 10, 2013 6:17 PM
    Thursday, January 10, 2013 5:33 PM
  • Thanks Dmitry. Which property of Recipient object should I use to get email address? I tried using ToString() but it's returning "System.__ComObject". My modified code looks like this:

    try
    {
        AppointmentItem appointment = null;
        for (int i = 1; i < Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count + 1; i++)
        {
            Object currentSelected = Globals.ThisAddIn.Application.ActiveExplorer().Selection[i];
            if (currentSelected is AppointmentItem)
            {
                appointment = currentSelected as AppointmentItem;
            }
        }
    
      string email = "";
      for (int i = 1; i < appointment.Recipients.Count - 1; i++)
      {
          if (appointment.Recipients[i].Type == 1)
              email = appointment.Recipients[i].ToString();
      }
    }
    catch (System.Exception ex)
    {
        LogException(ex);
    }

    Thursday, January 10, 2013 6:02 PM
  • Recipient.Address

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

    Thursday, January 10, 2013 6:03 PM
  • Dmitry, Recipient.Address is returning Active Directory Address. But I think I manage to pull email address through PropertyAccessor. Here is my modified code if someone else is interested.

    string email = "";
    PropertyAccessor pa;
    for (int i = 1; i < appointment.Recipients.Count - 1; i++)
    {
        if (appointment.Recipients[i].Type == 1)
        {
            pa = appointment.Recipients[i].PropertyAccessor;
            email = pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E");
        }
    }
    Thank you once again Dmitry. I appreciate your help for this pointer.
    • Marked as answer by Firoz A Thursday, January 10, 2013 6:17 PM
    • Unmarked as answer by Firoz A Thursday, January 10, 2013 6:29 PM
    Thursday, January 10, 2013 6:17 PM
  • The PR_SMTP_ADDRESS_A property is not guaranteed to be present in the recipient table.

    Use Recipient.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3002001F") to retrieve the PR_ADDRTYPE property. If it is "EX", use Recipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress. Be prepared to handle errors if any of the properiers returns null or raises an error.


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

    • Marked as answer by Firoz A Thursday, January 10, 2013 6:29 PM
    Thursday, January 10, 2013 6:22 PM
  • Got it! I changed my code per your suggestion.
    Thursday, January 10, 2013 6:29 PM