 |
|
 |
|
Next: Programming VBA: Making an appointment from a different account (OL 2007)
|
| Author |
Message |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 1) Posted: Fri Apr 20, 2007 10:26 am
Post subject: Can't get SMTP address of contact that shares email address of an Exchange user Archived from groups: microsoft>public>outlook>program_vba (more info?)
|
|
|
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 ("me@company.com").
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 |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 2) Posted: Fri Apr 20, 2007 11:33 am
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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 |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 3) Posted: Fri Apr 20, 2007 1:51 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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)
(jeffrey.buda@company.c".
I inspected this contact in MFC MAPI, and the property 0x804300E1
seems to contain the value I'm looking for,
"jeffrey.buda@company.com", but I'm afraid to use that unnamed
property that I've never heard of before.
Any other ideas?
Thanks,
Jeff |
|
| Back to top |
|
 |  |
|
Ken Slovak - [MVP - Outlo
|
External

Since: Oct 17, 2003 Posts: 3213
|
(Msg. 4) Posted: Fri Apr 20, 2007 2:06 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Jeff" <budajeff RemoveThis @gmail.com> wrote in message
news:1177089966.132379.259120@y5g2000hsa.googlegroups.com...
>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 ("me@company.com").
>
> 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
> |
|
| Back to top |
|
 |  |
External

Since: Nov 23, 2003 Posts: 1365
|
(Msg. 5) Posted: Fri Apr 20, 2007 2:06 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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 - [MVP - Outlook]" <kenslovak RemoveThis @mvps.org> wrote in message
news:urZdha3gHHA.4368@TK2MSFTNGP06.phx.gbl...
> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Jeff" <budajeff RemoveThis @gmail.com> wrote in message
> news:1177089966.132379.259120@y5g2000hsa.googlegroups.com...
>>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 ("me@company.com").
>>
>> 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
>>
> |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 6) Posted: Fri Apr 20, 2007 2:23 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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) (jeffrey.buda@company.com)" |
|
| Back to top |
|
 |  |
External

Since: Nov 23, 2003 Posts: 1365
|
(Msg. 7) Posted: Sat Apr 21, 2007 11:39 am
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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
"Jeff" <budajeff.RemoveThis@gmail.com> wrote in message
news:1177104194.944219.232700@y80g2000hsf.googlegroups.com...
> 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) (jeffrey.buda@company.com)"
>
> |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 8) Posted: Tue Apr 24, 2007 1:54 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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 |
|
| Back to top |
|
 |  |
External

Since: Nov 23, 2003 Posts: 1365
|
(Msg. 9) Posted: Tue Apr 24, 2007 2:47 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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
"Jeff" <budajeff.TakeThisOut@gmail.com> wrote in message
news:1177448051.738866.34680@b40g2000prd.googlegroups.com...
> 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
> |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 10) Posted: Thu Apr 26, 2007 7:43 am
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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 |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 10
|
(Msg. 11) Posted: Mon May 21, 2007 4:41 am
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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; |
|
| Back to top |
|
 |  |
External

Since: Nov 23, 2003 Posts: 1365
|
(Msg. 12) Posted: Mon May 21, 2007 10:52 am
Post subject: Re: Can't get SMTP address of contact that shares email address of an Exchange user [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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
"Jeff" <budajeff RemoveThis @gmail.com> wrote in message
news:1179747674.836204.259140@n15g2000prd.googlegroups.com...
> 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;
>
>
>
> |
|
| Back to top |
|
 |  |
External

Since: Jun 12, 2006 Posts: 710
|
(Msg. 13) Posted: Wed Aug 08, 2007 1:48 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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" |
|
| Back to top |
|
 |  |
External

Since: Nov 23, 2003 Posts: 1365
|
(Msg. 14) Posted: Wed Aug 08, 2007 5:04 pm
Post subject: Re: Can't get SMTP address of contact that shares email address of [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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
"John" <John DeleteThis @discussions.microsoft.com> wrote in message
news:764E5283-AE3A-46BE-97FC-DC21D9BBE872@microsoft.com...
> 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"
>
>
> |
|
| Back to top |
|
 |  |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|