A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Adding a Contact with multiple e-mail addresses to a Distribution



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old March 8th 09, 07:27 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Adding a Contact with multiple e-mail addresses to a Distribut

If you save the entry id, you can reopen the item at any later point using
Namespace.GetItemFromID.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
...
Dmitry,

Your clarification led me to do some further testing, which solved one of
my
two problems. Also, I realize that my earlier posts were somewhat
confusing.

My problem began when I tried to use the Outlook Object Model to go
through
the MAPIPDL entries in the Contacts folder. If you use the OOM, the
GetContact method does not work - it returns Null. You can see this with
OutlookSpy if you open a distribution list, retrieve a member and browse
the
Address Entry of the member.

My first post on 2/20 assumed that GetContact did not work and the only
data
available was the EntryName in the address entry. Ignore that.

My third post on 2/27 was a different approach to the problem - use the
AddressLists instead of the Contacts folder. This also fails in the way I
described.

HOWEVER - your posts on 3/1 and 3/3 made me realize that I had never tried
the GetContact method AFTER I switched from the OOM to your RDO objects. I
just tried the GetContact method on the RDOAddressEntry and it works! That
solves my first problem.

My second problem is still unsolved. Your post on 3/1 is a little
different
from my problem. You start by finding a contact, then creating a
distribution
list and adding a contact to it when you already have an object reference
to
the contact.

My application has an Access database with the name of an existing
distribution list and the name and address information for the contacts I
want to add to the list. I have to use information in the database to look
up
the contact and get an object reference for it. I need to extract a unique
identifier for the contact when I build the database so I can later use
the
identifier to look up the contact as I build the distribution list.

In other words,

step 1 - read the Contacts folder and build an Access database
step 2 - work with the data in Access to generate distribution lists
step 3 - read the database, look up the contacts and add them to the lists

I can't save the object reference in a database and use it later to get
the
object back. That is why I am trying to use the EntryIDs I found in the
property collection to get a unique key I can save and then use later to
get
the right contact.

I hope that clearly describes my problem. I can post all my code if you
want
it.

Thanks for your patience and for sticking with me on this project! You are
really helping me.

David Lingren


"Dmitry Streblechenko" wrote:

I do not suggest that you need to search a contact for a particular name,
just gave you an example of creating a new DL with a contact and then
reading the RDOAddressEntry.GetContact worked.
What is the value of the EntryID property when GetContcat returns null?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
...
Dimtry,

The solution you propose works in most cases, but not all. If the
contact
has a "Title" property, such as "Mr." or "Ms.", the Contacts.Items
search
will fail. The value in the "Name" field of the address entry is not
always
enough to retrieve the corresponding contact item. In my application, I
am
going through the address entries in a distribution list and trying to
find
the corresponding contact items. We've got thousands of contacts and
list
entries.

I have made some further progress on this problem, but haven't reached
the
end.

I used the Redemption.MAPIUtils.HrGetPropList method to retrieve the
properties for each AddressEntry. The entries that match a Contact item
have
a property 0x3A120102, the "PR_ORIGINAL_ENTRYID". The MAPI reference
says
"This property is one of the properties that contain information about
the
original source of a copied entry."

Going back to the Contact item that matches the AddressEntry, I find
properties 0x81140102, and 0x81150102 whose values match the 0x3A120102
property in the coprresponding address entry. It looks like these are
unique
identifiers for Email1Address, Email2Address, etc.

So, if I can do some sort of query like "find the item whose 0x8114 (or
0x8115 or ...) property is ..." I'm done. Is this possible?

Another problem - these properties are all PT_BINARY, i.e. byte arrays.
The
MAPI documentation says that entry ids are strings. How do I go from
the
byte
array to the equivalent string?


In the interim this is what seems to work for the data I've tested
against:

FullName = oAddressEntry.Name
lParen = InStr(1, FullName, "(")
If lParen 2 Then FullName = Left(FullName, lParen - 2)

Set oContactEntry = Nothing
SQLEncode MemberName, FullName ' handle single quotes in the name
Set oContacts = oItems.Restrict("SELECT * FROM folder WHERE [FullName]
LIKE
'%" & MemberName & "%'")
If oContacts.Count = 1 Then
Set oContactEntry = oContacts(1)
Else
Set oContact = Nothing
End If

It's not perfect...

Thanks for your continuing interest in this issue.

David Lingren



"Dmitry Streblechenko" wrote:

I hads no problem with the following script (assumign you have a
contact
named "Dmitry Streblechenko").

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Contacts = Session.GetDefaultFolder(olFolderContacts)
set DL = Contacts.Items.Add("IPM.DistList")
DL.DLName = "test contact"
set Contact = Contacts.Items("Dmitry Streblechenko") 'add email1
address
to
the DL
DL.AddContact Contact, 0
DL.Save

set AE = DL.Members(1)
set Contact = AE.GetContact
MsgBox Contact.FileAs

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







Ads
  #12  
Old March 9th 09, 04:20 AM posted to microsoft.public.outlook.program_vba
David Lingren
external usenet poster
 
Posts: 6
Default Adding a Contact with multiple e-mail addresses to a MAPIPDL

Dmitry,

Your suggestion solves part of the problem, but I did not make clear the
other part of my problem.

Using the RDO objects and GetContact I can find the Contact item that
matches a MAPIPDL member. I can't reliably find the "address type" in the
Contact that matches the MAPIPDL member entry (i.e. atEmail1 ... atOtherFax).

I have found that Outlook behaves oddly if you add a Contact to a MAPIPDL
and then later change or delete the e-mail address in the Contact item or
delete the entire Contact item. For example, try the following:

1. add a Contact to a MAPIPDL
2. delete the Contact
3. create a new e-mail message to the MAPIPDL

You will find that name and e-mail address for the deleted Contact still
appears in the message you create. If you open the MAPIPDL and double-click
on the entry for the deleted member, you get a "item has been deleted or
moved" warning. If you access the MAPIPDL from code, you get the deleted
item's MAPIPDL entry as if nothing has changed! So, if I call GetContact and
it fails, how do I tell the difference between a deleted Contact and an SMTP
entry that never had a Contact?

OR

1. add a Contact to a MAPIPDL
2. change the Contact's e-mail address
3. create a new e-mail message to the MAPIPDL

You will find that the message contains the new e-mail address, but if you
access the MAPIPDL you still get the OLD (wrong) address in the Recipient and
Address Entry objects! If you call GetContact, it will work but there's no
way to match the address in the MAPIPDL back to the correct address type in
the Contact.

Outlook obviously uses the hidden properties, such as the 0x3A120102
"PR_ORIGINAL_ENTRYID", to match the MAPIPDL member back to the Contact and
its e-mail and fax values. I haven't found a way to guarantee a match in code
using any of the Outlook OOM or Redemption objects.

So, you suggestion gets me to the Contact item (unless it's been deleted),
but not to the specific e-mail or fax value within the Contact. Can you help
with that?

Thanks, as always, for your help.


David Lingren

PS

For extra fun with my second (address change) example, open up the MAPIPDL
and click on "Select Members." Try adding the updated e-mail address to the
MAPIPDL. When you click OK, nothing changes. The contact is still in the
MAPIPDL with the old, wrong address and no warning or error is displayed.


"Dmitry Streblechenko" wrote:

If you save the entry id, you can reopen the item at any later point using
Namespace.GetItemFromID.

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


  #13  
Old March 10th 09, 07:10 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Adding a Contact with multiple e-mail addresses to a MAPIPDL

A deleted contact and a one-off SMTP recipient are the same for all
practical purposes: DL stores both the real entry id (that points to the
contact) and the one-off entry id that embeds the e-mail address.
In case of a on-off entry, the two entry ids are the same.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
...
Dmitry,

Your suggestion solves part of the problem, but I did not make clear the
other part of my problem.

Using the RDO objects and GetContact I can find the Contact item that
matches a MAPIPDL member. I can't reliably find the "address type" in the
Contact that matches the MAPIPDL member entry (i.e. atEmail1 ...
atOtherFax).

I have found that Outlook behaves oddly if you add a Contact to a MAPIPDL
and then later change or delete the e-mail address in the Contact item or
delete the entire Contact item. For example, try the following:

1. add a Contact to a MAPIPDL
2. delete the Contact
3. create a new e-mail message to the MAPIPDL

You will find that name and e-mail address for the deleted Contact still
appears in the message you create. If you open the MAPIPDL and
double-click
on the entry for the deleted member, you get a "item has been deleted or
moved" warning. If you access the MAPIPDL from code, you get the deleted
item's MAPIPDL entry as if nothing has changed! So, if I call GetContact
and
it fails, how do I tell the difference between a deleted Contact and an
SMTP
entry that never had a Contact?

OR

1. add a Contact to a MAPIPDL
2. change the Contact's e-mail address
3. create a new e-mail message to the MAPIPDL

You will find that the message contains the new e-mail address, but if you
access the MAPIPDL you still get the OLD (wrong) address in the Recipient
and
Address Entry objects! If you call GetContact, it will work but there's no
way to match the address in the MAPIPDL back to the correct address type
in
the Contact.

Outlook obviously uses the hidden properties, such as the 0x3A120102
"PR_ORIGINAL_ENTRYID", to match the MAPIPDL member back to the Contact and
its e-mail and fax values. I haven't found a way to guarantee a match in
code
using any of the Outlook OOM or Redemption objects.

So, you suggestion gets me to the Contact item (unless it's been deleted),
but not to the specific e-mail or fax value within the Contact. Can you
help
with that?

Thanks, as always, for your help.


David Lingren

PS

For extra fun with my second (address change) example, open up the MAPIPDL
and click on "Select Members." Try adding the updated e-mail address to
the
MAPIPDL. When you click OK, nothing changes. The contact is still in the
MAPIPDL with the old, wrong address and no warning or error is displayed.


"Dmitry Streblechenko" wrote:

If you save the entry id, you can reopen the item at any later point
using
Namespace.GetItemFromID.

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




 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple e-mail addresses merged into distribution list red14red Outlook - Using Contacts 2 October 1st 08 08:17 PM
Adding Distribution list to an e-mail with multiple mailboxes Jamie Outlook and VBA 1 May 20th 07 10:13 PM
Adding email addresses to an old distribution list cjm563 Outlook - Using Contacts 5 January 12th 07 08:35 PM
Adding a contact to one or multiple distribution lists Andy E Outlook - Using Contacts 4 December 28th 06 07:21 PM
Displaying multiple e-mail addresses for one contact Tony Reynolds Outlook - Using Contacts 1 February 16th 06 05:15 PM


All times are GMT +1. The time now is 05:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.