1
votes

is it a bug in outlook?

i've created a local Contact list card, and i gave him in the address field an exchange user address. (double click on that address, see that its exchange).

when i try to get the address using MAPI - i can't, the problem is this, when i check the AddressEntry object, i get the following:

  • Type = "EX"
  • Address = "/o=.../ou=Exchange..."/cn=Recipients/cn=Name
  • Class = olAddressEntry
  • AddressEntryUserType = olOutlookContactAddressEntry

when i checked in OutlookSpy - no MAPI properties, so i can't get PR_SMTP_ADDRESS nor PR_EMS_AB_PROXY_ADDRESSES, also, this is not SMTP so i have no valid address.


i checked other users and those are the properties (which it works):

Real exchange user recipient, same email address as the exchange one, but it was created without autocorrect to the exchange user, so it stays smtp:

  • Type = "SMTP"
  • Address = "[email protected]"
  • Class = olAddressEntry
  • AddressEntryUserType = olExchangeUserAddressEntry

Regular address entry

  • Type = "EX"
  • Address = "/o=.../ou=Exchange..."/cn=Recipients/cn=Name
  • Class = olAddressEntry
  • AddressEntryUserType = olOutlookContactAddressEntry

if i double click on the "exchange" local contact, it opens exchange window of its properties, if i open the "regular one i created manually", it opens the "SMTP" address window.

any workaround i can do?

thanks.

2

2 Answers

2
votes

It didn't work in way "Dmitry Streblechenko" suggested because for some reason ContactItem.Email1EntryId, ContactItem.Email2EntryId and ContactItem.Email3EntryId contains not id but some wrong random data (even some html tags) - office 2016.

But it finally worked with following code

 using (var pa = new InteropWrapper<Outlook.PropertyAccessor>(contact.innerObject.PropertyAccessor))
            {
                String EMAIL1_ENTRYID = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80850102";
                string emailEntryID = pa.innerObject.BinaryToString(pa.innerObject.GetProperty(EMAIL1_ENTRYID));

                using (var rs = new InteropWrapper<Outlook.NameSpace>(Globals.ThisAddIn.Application.Session))
                {
                    rs.innerObject.Logon();
                    using (var addressEntry = new InteropWrapper<Outlook.AddressEntry>(rs.innerObject.GetAddressEntryFromID(emailEntryID)))
                    using (var exchangeUser = new InteropWrapper<Outlook.ExchangeUser>(addressEntry.innerObject.GetExchangeUser()))
                    {
                        return exchangeUser.innerObject.PrimarySmtpAddress;
                    }
                }
            }

where InteropWrapper<T> just IDisposable wrapper around com object - it does Marshal.ReleaseComObject(innerObject) on dispose. So you can do everything without it by using Marshal.ReleaseComObject() directly.

just in case if someone need email 2 and email 3 including them here

String EMAIL2_ENTRYID = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80950102";
String EMAIL3_ENTRYID = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80A50102";

Hope it will save someones time! I've spent like a day on it.

1
votes

If you have an EX type contact, use the value of the ContactItem.Email1EntryId property to call Namespace,GetAddressEntryFromId, then read the AddressEntry.GetExchangeUser.PrimarySmtpAddress property.