Can't get SMTP address of contact that shares email address of an Exchange user

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I created a contact in Outlook 2003, then I gave that contact an email
address that matches the email address of an Exchange user. When I
access this contact using Outlook COM, I now get the Exchange address
("//o=Company/ou=First Administrative Group/cn=Recipients/cn=0001234")
instead of the address I typed into the contact ("(e-mail address removed)").

I implemented Ken Slovak's suggestions "To get the SMTP address
instead of the Exchange distinguished name", found here (http://
groups.google.com/group/microsoft.public.outlook.program_vba/
browse_thread/thread/60231601429b1156/811ce165ff5854df?lnk=st&q=outlook
+com+get+smtp+email+address+of+contact&rnum=3#811ce165ff5854df)

I also implemented Dmitry's instructions "Default SMTP address of an
Exchange user" found here (http://www.dimastr.com/redemption/
utils.htm)

I think those instructions don't apply b/c of the fact that the
ContactItem i created isn't really an Exchange user, but merely shares
an email address w/ an Exchange user.

I know how to get the SMTP addresses from a MailItem, so please don't
give me help with that.

Any ideas?

Thanks in advance!
Jeff

Here's (C#) code that illustrates the problem. I included the return
values in the comments:

//get the contact I created for this test...
Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace ns = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder folder =
ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
ContactItem contact = folder.Items[1] as ContactItem;
MAPIUtils utils = new MAPIUtils();

//define properties...
int PR_EMS_AB_PROXY_ADDRESSES = unchecked((int)0x800f101e);
const int g_PR_SMTP_ADDRESS_W = unchecked((int)0x39FE001E);

//analyze the ContactItem
string emailAddress = contact.Email1Address;//o=Company/ou=First
Administrative Group/cn=Recipients/cn=0001234
string emailAddressType = contact.Email1AddressType;//EX
object contactProp1 = utils.HrGetOneProp(contact.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object contactProp2 = utils.HrGetOneProp(contact.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null

//analyze the AddressEntry
Redemption.AddressEntry addressEntry =
utils.GetAddressEntryFromID(contact.EntryID) as
Redemption.AddressEntry;
string addressEntryAddress = addressEntry.Address;//null
object addressEntryProp1 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object addressEntryProp2 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null
 
The Exchange address is really only valid for an entry in the GAL. If you
have a contact that shares that address with the GAL entry then you might be
able to do what you've done but otherwise it's useless. Just change the
contact address to the SMTP version and forget about using an X.400 address
for that. The MAPI fields you mention are only there for Recipients or
AddressEntries that correspond to GAL entries.




Jeff said:
I created a contact in Outlook 2003, then I gave that contact an email
address that matches the email address of an Exchange user. When I
access this contact using Outlook COM, I now get the Exchange address
("//o=Company/ou=First Administrative Group/cn=Recipients/cn=0001234")
instead of the address I typed into the contact ("(e-mail address removed)").

I implemented Ken Slovak's suggestions "To get the SMTP address
instead of the Exchange distinguished name", found here (http://
groups.google.com/group/microsoft.public.outlook.program_vba/
browse_thread/thread/60231601429b1156/811ce165ff5854df?lnk=st&q=outlook
+com+get+smtp+email+address+of+contact&rnum=3#811ce165ff5854df)

I also implemented Dmitry's instructions "Default SMTP address of an
Exchange user" found here (http://www.dimastr.com/redemption/
utils.htm)

I think those instructions don't apply b/c of the fact that the
ContactItem i created isn't really an Exchange user, but merely shares
an email address w/ an Exchange user.

I know how to get the SMTP addresses from a MailItem, so please don't
give me help with that.

Any ideas?

Thanks in advance!
Jeff

Here's (C#) code that illustrates the problem. I included the return
values in the comments:

//get the contact I created for this test...
Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace ns = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder folder =
ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
ContactItem contact = folder.Items[1] as ContactItem;
MAPIUtils utils = new MAPIUtils();

//define properties...
int PR_EMS_AB_PROXY_ADDRESSES = unchecked((int)0x800f101e);
const int g_PR_SMTP_ADDRESS_W = unchecked((int)0x39FE001E);

//analyze the ContactItem
string emailAddress = contact.Email1Address;//o=Company/ou=First
Administrative Group/cn=Recipients/cn=0001234
string emailAddressType = contact.Email1AddressType;//EX
object contactProp1 = utils.HrGetOneProp(contact.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object contactProp2 = utils.HrGetOneProp(contact.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null

//analyze the AddressEntry
Redemption.AddressEntry addressEntry =
utils.GetAddressEntryFromID(contact.EntryID) as
Redemption.AddressEntry;
string addressEntryAddress = addressEntry.Address;//null
object addressEntryProp1 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object addressEntryProp2 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null
 
My problem is that I need to discover the SMTP address from the
ContactItem, but all can get is the X.400 address. Is there any way to
get the SMTP address in this case?

Your comment "Just change the contact address to the SMTP version",
implies that I know what the SMTP address is, but I do not. The SMTP
address is the information I'm trying to get via accessing the
ContactItem.

Thanks again!
Jeff
 
You can use the value of the Email1EntryId property to call
Namespace.GetRecipientFromID, then use any of the applicable tricks to get
the SMTP address from the returned Recipient.AddressEntry object.
If you are using Redemption, you can simply call
RDOSession.GetAddressEntryFromID, then read the RDOAddressEntry.SmtpAddress
property.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Ken Slovak - said:
The Exchange address is really only valid for an entry in the GAL. If you
have a contact that shares that address with the GAL entry then you might
be able to do what you've done but otherwise it's useless. Just change the
contact address to the SMTP version and forget about using an X.400
address for that. The MAPI fields you mention are only there for
Recipients or AddressEntries that correspond to GAL entries.




Jeff said:
I created a contact in Outlook 2003, then I gave that contact an email
address that matches the email address of an Exchange user. When I
access this contact using Outlook COM, I now get the Exchange address
("//o=Company/ou=First Administrative Group/cn=Recipients/cn=0001234")
instead of the address I typed into the contact ("(e-mail address removed)").

I implemented Ken Slovak's suggestions "To get the SMTP address
instead of the Exchange distinguished name", found here (http://
groups.google.com/group/microsoft.public.outlook.program_vba/
browse_thread/thread/60231601429b1156/811ce165ff5854df?lnk=st&q=outlook
+com+get+smtp+email+address+of+contact&rnum=3#811ce165ff5854df)

I also implemented Dmitry's instructions "Default SMTP address of an
Exchange user" found here (http://www.dimastr.com/redemption/
utils.htm)

I think those instructions don't apply b/c of the fact that the
ContactItem i created isn't really an Exchange user, but merely shares
an email address w/ an Exchange user.

I know how to get the SMTP addresses from a MailItem, so please don't
give me help with that.

Any ideas?

Thanks in advance!
Jeff

Here's (C#) code that illustrates the problem. I included the return
values in the comments:

//get the contact I created for this test...
Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace ns = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder folder =
ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
ContactItem contact = folder.Items[1] as ContactItem;
MAPIUtils utils = new MAPIUtils();

//define properties...
int PR_EMS_AB_PROXY_ADDRESSES = unchecked((int)0x800f101e);
const int g_PR_SMTP_ADDRESS_W = unchecked((int)0x39FE001E);

//analyze the ContactItem
string emailAddress = contact.Email1Address;//o=Company/ou=First
Administrative Group/cn=Recipients/cn=0001234
string emailAddressType = contact.Email1AddressType;//EX
object contactProp1 = utils.HrGetOneProp(contact.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object contactProp2 = utils.HrGetOneProp(contact.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null

//analyze the AddressEntry
Redemption.AddressEntry addressEntry =
utils.GetAddressEntryFromID(contact.EntryID) as
Redemption.AddressEntry;
string addressEntryAddress = addressEntry.Address;//null
object addressEntryProp1 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
PR_EMS_AB_PROXY_ADDRESSES);//null
object addressEntryProp2 = utils.HrGetOneProp(addressEntry.MAPIOBJECT,
g_PR_SMTP_ADDRESS_W);//null
 
Email1EntryId is not valid in this case. Passing it into
NameSpace.GetRecipientFromID() throws an exception ("Additional
information: Could not open the item. Try again.").

A visual inspection of Email1EntryId reveals that it's not a binary
string consisting of characters [0...9, A...F], but rather it just
looks like it accessed part of the memory that stores the X500
address. The invalid value is "^\0rey Buda (ABC SS&S)
([email protected]".

I inspected this contact in MFC MAPI, and the property 0x804300E1
seems to contain the value I'm looking for,
"(e-mail address removed)", but I'm afraid to use that unnamed
property that I've never heard of before.

Any other ideas?

Thanks,
Jeff
 
Here's some values for the contact via OutlookSpy:

Email1EntryID = "^"
Email1Address = "/o=Company/ou=First Administrative Group/
cn=Recipients/cn=0012345;"
Email1AddressType = "EX"
Email1DisplayName = "Jeff Buda (ABC SS&S) ([email protected])"
 
Ouch! Looks like a bug in Outlook... And the same problem exists in Outlook
2007 - it just does not convert the binary data to a hex string.
You can try to read the Email1EntryID property using MAPI, CDO 1.21 or
Redemption (the property is {00062004-0000-0000-C000-000000000046}, 0x8085,
PT_BINARY).
<plug> RDOContact.Email1EntryID along with RDOSession.GetAddressEntryFromID
in Redemption works just fine </plug>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks for the help. I confirmed that your RDO library does get the
SMTP-formatted address that I need. I would like to consider some
other options before I use that work-around.

Regarding your suggestion on reading the property via MAPI, is this
how you would do it via Redemption?

Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace nameSpace = app.GetNamespace("MAPI");
ContactItem contact =
nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items[1]
as ContactItem;
MAPIUtils mapiUtils = new MAPIUtils();
object result = mapiUtils.GetIDsFromNames(contact.MAPIOBJECT,
"00062004-0000-0000-C000-000000000046", 0x8085, false);


The call to GetIDsFromNames results in this COMException:

Additional information: Error in _HrGetIDsFromNames - CLSIDFromString
0x800401F3


I'm not sure if that error means that I'm using MAPIUtils wrong, or if
Outlook has a bug, as you suggested.

Thanks,
Jeff
 
That looks fine, you just need to include {} when passing the GUID string:

object result = mapiUtils.GetIDsFromNames(contact.MAPIOBJECT,
"{00062004-0000-0000-C000-000000000046}", 0x8085, false);

Also don't forget to "or" the returned value with PT_BINARY (0x0102). You
can then use MAPIUtils.HrGetOneProp to read that binary prop (variant array
is returned for the binary props), then convert it to a hex string using
MAPIUtils.HrArrayToString


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I did take this issue up w/ Microsoft Support. They are still trying
to determine if this is a bug or not. The support guy said that their
usual workaround for this issue is to use CDO, but they would not
suggest that solution to me as CDO is not supported when working w/
a .Net language as I am.

Their other workaround they tried was to use the
System.DirectoryServices namespace. Basically, parse the X500 address
to find the Exchange user name, then user DirectoryServices to look up
that Exchange user, then use the "proxyaddresses" property to get the
SMTP formatted addresses. However, the support guy could not come up
w/ a DirectorySearcher query string that would work in my environment.

Finally, he suggested that I get the X500 address, parse out the
Exchange user name, put that into a temporary ContactItem, save it,
then parse the email display name which will include SMTP address.
I'll probably do that for the short term, and then next cycle we'll
upgrade to the latest Redemption library and use the RDO method you
described above.

I'll also try getting the property via MAPI, applying your suggested
changes to the code I posted.

Jeff
 
Here's the working code for future reference:

Outlook._Application olApp = new Outlook.ApplicationClass();

Outlook._NameSpace olNS = olApp.GetNamespace("MAPI");

Outlook.MAPIFolder oFolder =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

ContactItem contact =
olNS.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items[1] as
ContactItem;

MAPIUtils mapiUtils = new MAPIUtils();

int result = mapiUtils.GetIDsFromNames(
contact.MAPIOBJECT,
"{00062004-0000-0000-C000-000000000046}",
0x8085,
false);

object value = mapiUtils.HrGetOneProp(contact.MAPIOBJECT, result);

string entryID = mapiUtils.HrArrayToString(value);

Redemption.AddressEntry addressEntry =
mapiUtils.GetAddressEntryFromID(entryID);

const int g_PR_SMTP_ADDRESS_W = unchecked((int)0x39FE001E);

string smtpEmailAddress =
mapiUtils.HrGetOneProp(addressEntry.MAPIOBJECT, g_PR_SMTP_ADDRESS_W)
as string;
 
Keep in mind that PR_SMTP_ADDRESS is only available in the online mode. In
the cached mode (which is used by default), you need to use
PR_EMS_AB_PROXY_ADDRESSES property.
Since you are using Redemption, why not use RDOContact.Email1EntryID along
with RDOSession.GetAddressEntryFromID as I suggested in my previous reply?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi All,

For what it's worth getting contact info in SMTP format for me was tough.
Turns out half of my contacts are coded as SMTP when they're really exchange
(EX or X500) type. Anyhow, this thread was very useful, so to give back
some...please find below my Visual Basic Scripting (VBS) code to extract SMTP
address from the contact book, evaluate them (to see if they are really SMTP
or exchange), contact the Exchange to get the SMTP value if they are
exchange, and dump it all to an Excel spreadsheet.

Thanks to Dmitri for that awesome Redemption work, without which this would
have been dare I say inprobable!!!

Regards!

'**************************************
'**************************************
'**************************************
Dim myItem
Dim myContacts
Dim myContact
Dim addressEntry
Dim RDOSession
Dim RDOAddressEntry
Dim Recipient

Dim objXL
Dim myOlApp
Dim utils
Dim myNamespace
Dim value

Set objXL = WScript.CreateObject("Excel.Application")
set utils = CreateObject("Redemption.MAPIUtils")
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
set RDOSession = CreateObject("Redemption.RDOSession")
RDOSession.MAPIOBJECT=myOlApp.Session.MAPIOBJECT
Set myContacts = RDOSession.GetDefaultFolder(10).Items

objXL.Visible = TRUE
objXL.WorkBooks.Add
objXL.Columns(1).ColumnWidth = 40
objXL.Columns(2).ColumnWidth = 40
objXL.Columns(3).ColumnWidth = 40
objXL.Cells(1, 1).Value = "Name"
objXL.Cells(1, 1).Font.Bold = TRUE
objXL.Cells(1, 2).Value = "Nickname"
objXL.Cells(1, 2).Font.Bold = TRUE
objXL.Cells(1, 3).Value = "Email Address"
objXL.Cells(1, 3).Font.Bold = TRUE

Dacount = 1

For each myContact in myContacts

if TypeName(myContact)= "RDOContactItem" Then

result =
utils.GetIDsFromNames(myContact.MAPIOBJECT,"{00062004-0000-0000-C000-000000000046}",&H8085,false)
value = utils.HrGetOneProp(myContact.MAPIOBJECT, result)

if not isempty(value) then

Dacount = Dacount + 1
entryID = utils.HrArrayToString(value)

set RDOAddressEntry = RDOSession.GetAddressEntryFromID( entryID)
smtpEmailAddress= RDOAddressEntry.SmtpAddress

objXL.Cells(Dacount, 1).value = myContact.FirstName+"
"+myContact.LastName
objXL.Cells(Dacount, 2).value = myContact.NickName

if mid(smtpEmailAddress,1,2) = "/o" then

foundSMTP = InStr(1,smtpEmailAddress,"SMTP:")
if foundSMTP > 0 then
smtpEmailAddress=mid(smtpEmailAddress,foundSMTP+5)
objXL.Cells(Dacount, 3).value = smtpEmailAddress
else
foundSMTP = InStr(1,smtpEmailAddress,"Recipients/cn=")
smtpEmailAddress=mid(smtpEmailAddress,foundSMTP+14)
set Recipient = utils.CreateRecipient(smtpEmailAddress,
0,0)

if Recipient.Resolved then
objXL.Cells(Dacount, 3).value =
Recipient.AddressEntry.SMTPAddress
else
smtpEmailAddress = "***Not avialable***"
objXL.Cells(Dacount, 3).value = smtpEmailAddress
objXL.Cells(Dacount, 3).Font.Bold = TRUE
end if
end if

else
if smtpEmailAddress = "" then
smtpEmailAddress = "***Not avialable***"
objXL.Cells(Dacount, 3).value = smtpEmailAddress
objXL.Cells(Dacount, 3).Font.Bold = TRUE
end if

objXL.Cells(Dacount, 3).value = smtpEmailAddress

end if

end if

end if
next

msgbox "Contact extraction done!",,"Contact extractor"
 
A couple of fcomments:

1. There is not reason to use MAPIUtils - RDOContactItem (derived from
RDOMail, derived in turn from MAPIProp), exposes the GetIDsFromNames. Or you
can simply pass the property tag as a DASL name when accessing the property
through Fields. More than that, you can simply read the
RDOContactItem.Email1Address and RDOContactItem.Email1EntryID properties.
2. There is no reason to parse anything - RDOAddressEntry.SmtpAddress is
guaranteed to return a valid SMTP address or an empty string.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi All !

I know how to create Exchange contact in mailbox but I can’t link my contact to a Exchange Mailbox (Global Access List).


RDOMail item = folder.Items.Add("IPM.Contact");
RDOContactItem contact = (RDOContactItem)item;
contact.Email1AddressType = “EX”;
contact.Email1Address = "/o=Exchange-staples/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=desdemonias"; //legacyExchangeDN
contact.Save();

When I click on EmailAddress Field Contact via Outlook, it doesn’t link to GAL Exchange user.

I also try this code but it doesn’t work too.

RDOMail item = folder.Items.Add("IPM.Contact");
RDOContactItem contact = (RDOContactItem)item;
String Email1AddressTypeTmp = contact.Email1AddressType;
String Email1AddressTmp = contact. Email1Address;
String Email1AddressIDTmp= contact.Email1EntryID;

contact.Email1AddressType = Email1AddressTypeTmp;
contact.Email1Address = Email1AddressTmp;
contact.Email1EntryID = Email1AddressIDTmp;
contact.Save();

I think, I need to initialize another properties but I don’t know wich one…


Thank you so much for your help !

Olivier Lemonnier





EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
Back
Top