?
Solved

Retrieve Outlook 2000 Address Book Group Members

Posted on 2003-02-25
12
Medium Priority
?
677 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
  • 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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 

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

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Organisation is organized in a pattern to flow the day to day business, every application and system is interdepended on each other and when very important “Exchange Server downtime” happened.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

601 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