Obtain SMTP Address using CDO in an un-managed environment

You can use the AddressEntry.Fields(PR_SMTP_ADDRESS) method where PR_SMTP_ADDRESS is 0x39FE001E.

Here are two examples of it:

' MAPI property tag for SMTP address

        ' Get first message from inbox

        Set objFolder = objSession.Inbox

        Set objMessages = objFolder.Messages

        Set objMessage = objMessages.GetFirst()

       

        ' Get address

        Set objAddressEntry = objMessage.Sender

        strEMailAddress = objAddressEntry.Address

       

        ' Check if it is an Exchange object

        If Left(strEMailAddress, 3) = "/o=" Then

          ' Get the SMTP address

          strAddressEntryID = objAddressEntry.ID

          'strEMailAddress = objSession.GetAddressEntry(strAddressEntryID).Fields(CdoPR_EMAIL).Value

          'strEMailAddress = objSession.GetAddressEntry(strAddressEntryID).Fields(CdoPR_EMAIL).Value

          strEMailAddress = objSession.GetAddressEntry(strAddressEntryID).Fields(g_PR_SMTP_ADDRESS_W).Value

          strEMailAddress = objSession.GetAddressEntry(strAddressEntryID).Fields(g_PR_SMTP_ADDRESS_W).Value

        End If

              

        ' Display the SMTP address of current user

        MsgBox "SMTP address of current user: " & strEMailAddress

--------------------------------

In c# you can access it similarly like this:

                MAPI.Session mysession = CreateObject("MAPI.Session") as MAPI.Session;

                mysession.MAPIOBJECT = objNameSpace.Session.MAPIOBJECT;

                               

                MAPI.AddressEntry entries = mysession.CurrentUser as MAPI.AddressEntry;

               

                string correo = entries.Address.ToString();

                string entryID = string.Empty;

                int id = int.Parse("39FE001F",System.Globalization.NumberStyles.HexNumber,null);

               

                if (correo.Substring(0, 3) == "/o=")

                {

                    entryID = entries.ID.ToString();

                    User = ((((mysession.GetAddressEntry(entryID) as MAPI.AddressEntry)).Fields as MAPI.Fields).get_Item(id, null) as MAPI.Field).Value.ToString();

                }

                else

                    User = correo;

MFCMapi - https://mfcmapi.codeplex.com/  is a great tool to use to understand the exchange store and message attributes.

Go ahead and have a play