Occasional fault when getting email address of shared folder owner RRS feed

  • Question

  • My app needs to gather information about the calendar folders available to the user so it can then work with these folders. In the case of shared calendars it also needs the email address of the calendar owner in order to check licencing.

    The code to get the email address sometimes works and sometimes returns an error

     The main routine includes this

    oNS = Info.OutlookApplication.GetNamespace("MAPI");
    oRecipient = RecipientFromDisplayName(displayName);
    ownersEmailAddress = EmailAddressFromRecipient(oRecipient);

    and the code to get the email address is

    private string EmailAddressFromRecipient(Recipient oRecipient)
                AddressEntry oAddressEntry = null;
                string smtpAddress = string.Empty;
                if (oRecipient != null)
                        oAddressEntry = oRecipient.AddressEntry;
                    catch (System.Exception ex)
                        if (ex.Message == "Cannot resolve recipient.")
                            Log.Record("Cannot resolve recipient.");
                        return string.Empty;
                    if (oAddressEntry.Type.ToLower() == "ex")
                        const string PR_SMTP_ADDRESS = "";
                        PropertyAccessor pa = oRecipient.PropertyAccessor;
                        smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
                if (oAddressEntry != null) Marshal.ReleaseComObject(oAddressEntry);
                return smtpAddress;

    This seems to work with some folders but not others.

    Any ideas about what I need to do would be welcome.

    Mike VE

    Thursday, August 20, 2015 7:50 AM


All replies

  • I forgot to include details of the error. It occurs on the line 

    oAddressEntry = oRecipient.AddressEntry;

    and the details are

    Type: System.Runtime.InteropServices.COMException
    Message: The attempted operation failed.  An object could not be found.
    Site: get_AddressEntry

    Mike VE

    Thursday, August 20, 2015 8:08 AM
  • Hello Mike,

    Did you try to call the Resolve or ResolveAll methods before accessing the AddressEntry property?

    In Outlook 2007 and later you can use the GetExchangeUser method of the AddressEntry class which returns an ExchangeUser object that represents the AddressEntry if the AddressEntry belongs to an Exchange AddressList object such as the Global Address List (GAL) and corresponds to an Exchange user. Then you can use the PrimarySmtpAddress property to get the primary Simple Mail Transfer Protocol (SMTP) address for the ExchangeUser.

    In earlier Outlook versions you need to find the recipient in the Outlook address book by using the IAddrBook.ResolveName method, then reach the IMailUser interface with the IAddrBook.OpenEntry method and get the PR_EMS_AB_PROXY_ADDRESSES property. See HowTo: Convert Exchange-based email address into SMTP email address for more information.

    • Marked as answer by Mike VE Thursday, August 20, 2015 6:14 PM
    Thursday, August 20, 2015 9:19 AM
  • This happens if the address entry no longer exists, e.g. if the corresponding GAL object is gone.

    What is the implementation of the RecipientFromDisplayName method?

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 20, 2015 5:17 PM
  • No Eugene I had not used Resolve. I should have done. I would still not have got a Recipient object but it would have been handled cleanly without an exception.

    Yes Dmitry, that makes sense. I contacted the user who sent the error message and it turns out that the user who owned the shared calendar had changed her email.

    Now I understand what happened I can rewrite the code to handle the situation better.

    Thanks to you both.

    Mike VE

    Thursday, August 20, 2015 6:17 PM