?
Solved

Retrieve Outlook 2000 Address Book Group Members

Posted on 2003-02-25
12
Medium Priority
?
670 Views
Last Modified: 2012-08-13
Using the Outlook 9 & Office 9 object libraries how can I access individual emails from an email group contained in the address book? For instance say a user has an email group called 'Sales Team' that contains three email adresses bsmith@sales.com, csmith@sales.com, and dsmith@sales.com. How can I retrieve the three addresses from the 'Sales Team' group?
It seems that the recipients collection of the mail object does not expose emails unless they're idividually added to the email, so there must be some other way to programmatically derive them. The only thing I can seem to get from the recipients collection is the name of the group.


Thx
0
Comment
Question by:amehrich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 8022758
Assuming that I understand you correction that a user is addressing an e-mail w/ a distribution list then you would make the following jumps in logic.

1) Addressing an e-mail to a distribution list.  An e-mail is a MailItem in code.  MailItem exploses a recipients collection.

2) From the recipients collection, you can get a recipient.

3) A recipient can be an individual or distribution list.  Therefore you would check the Recipient.DisplayType property to see if it is a user (single person) or a distribution list.

4) If distribution list you would then get the AddressEntry object via Recipient.AddressEntry

5) The AddressEntry object exposes a members method that returns an AddressEntries collection.

6) You can reinterate the AddressEntries collection to get the users names/email addresses.
0
 

Author Comment

by:amehrich
ID: 8025684
Neo mvps

I think I follow you, but it doesn't seem to be working. I've noticed that when I send an email to just a distribution list and read the display type it always comes back as 0 (olUser). Any ideas what's causing this? Here's a condensed version of the code...

'declare mail item
Private WithEvents objMailItem As Outlook.MailItem

'item send event
Private Sub objOutlook_ItemSend(ByVal Item As Object, Cancel As Boolean)

 'set referrence to the mail item
 Set objMailItem = Item

 'display the recipient type
 MsgBox ("Disaply Type= " & objMailItem.Recipients.Item  
 (1).DisplayType)

End Sub
0
 

Expert Comment

by:allanhsu
ID: 8028074
Does this solution only apply to mail that is being sent from the server?  The reason I ask is I have an archive PST file not attached to the original server, and I would like to find out the individuals on the distribution lists at the time of the email.  Thanks for your help.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:amehrich
ID: 8028166
allanhsu,

If you're talking to me the solution I'm working on involves creating a COM add-in project with Visual Basic 6. In the case of COM add-in's they are loaded on the client machine via the Outlook interface.
By referrencing the Outlook and Office object libraries in Visual Basic you can insert logic into the send event of your add-in, which is triggered when the user clicks the send button.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 8030197
What do you get back if you change:

MsgBox ("Disaply Type= " & objMailItem.Recipients.Item  
(1).DisplayType)

to:

MsgBox ("Name= " & objMailItem.Recipients.Item  
(1).Name)
0
 

Author Comment

by:amehrich
ID: 8030618
Neo_mvps

When I make the requested change I get Name=TEST. 'TEST' is the name I assigned to the distribution list, but the type is still 0. Any ideas?

Thx
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 8033008
Not a clue.  I'll have to setup a machine with outlook 2000 and do some testing to see what is up.  Is Outlook in corp/workgroup or internet mail only mode?
0
 

Author Comment

by:amehrich
ID: 8033379
Neo_mvps,

I'm setup to use Internet only mail. Thanks again for your efforts, I'm increasing the points...
0
 
LVL 4

Accepted Solution

by:
mesch earned 1500 total points
ID: 8075292
amehrich;

Last question. Do you want to use your COM add-in in an Exchange environment?

Here is a sample that should work. If you get the distributionlist (DL) from a personal adressbook or a contact folder/addressbook [oMember.Address] returns the SMTP-Address of the member.
Constant 1 (olDistList) is for DLs in Exchange Directory
Constant 5 (olPrivateDistList) is for DLs from PAB or Contact folder.
If you get an Exchange DL (olDistList) from the GAL you will get the X400-Address which can be resolved as well.

Sub CommandButton1_Click()

For Each oRecipient In Item.Recipients
  If oRecipient.AddressEntry.DisplayType = 1 OR oRecipient.AddressEntry.DisplayType = 5 Then '1 = Exchange DL 5 = Private DL
    For Each oMember In myRecipient.AddressEntry.Members
      MsgBox oMember.Address
    Next
  End If
Next

End Sub

</norbert>
   
0
 

Author Comment

by:amehrich
ID: 8075398
mesch,

i don't want to use it in an Exchange environment. in the testing that i've done already i've noticed that regardless of the email type the DisplayType is always 0. if i send an email to a single email address the type is 0, and if i send an email to a distribution list containing 3 emails the type again is 0. im not sure why that is...
0
 
LVL 4

Expert Comment

by:mesch
ID: 8076066
Okay where do you save/store your distribution lists? Contacts? PAB(Personal Address Book)?

How would you reference to the AddressEntry?
Through the recipients collection of the current item?
Through user choice in the address book?

In your posted code I miss the AddressEntry. I know that the Recipient Object as the DisplayType property as well.

'display the recipient type
MsgBox ("Disaply Type= " & objMailItem.Recipients.Item  
(1).AddressEntry.DisplayType)

One thing more. Are the recipients of your item resolved?

If you like post you code for a better understanding.
</norbert>
0
 

Author Comment

by:amehrich
ID: 8080232
mesch,

- the 'TEST' distribution list contains two emails and is in Contacts.
- i'm trying to referrence the address entry by way of the recipients collection of the current mail item.
- my code is located in the itemsend event.

here's the code that i'm trying to run which is resulting in the error below. it seems to be blowing up on the for statement. here's the error...

MS Outlook Error -2147467262
The messaging interface has returned an unkown error. If the problem persists, restart Outlook.


Dim objNS, objGAL, objAddressEntries, objMember  

Set objNS = objOutlook.GetNamespace("MAPI")
Set objGAL = objNS.AddressLists("Contacts")
Set objAddressEntries = objGAL.AddressEntries

For Each objMember In objAddressEntries("TEST").Members
    MsgBox (objMember.Name)
Next



thanks
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question