View Single Post
  #2  
Old July 5th 06, 09:05 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Sender Properties

Outlook doesn't maintain a direct programmatic link between the sender of an
e-mail and a possible Contact record that was previously created from that
sender. Your only choice is to use the sender's name or e-mail address with
the Restrict or Find method on a folder's Items collection (or the
AdvancedSearchObject) to retrieve an actual ContactItem object.

Here's a function for using the e-mail address to retrieve a Contact. Just
pass a previously instantiated MAPIFolder object that is stores the Contact
in question (you can use NameSpace.GetDefaultFolder to get the MAPIFolder
object for the default Contacts folder if you like).

Function GetContactByEmailAddress(email As String, ContactFolder As
Outlook.MAPIFolder) As ContactItem
Dim objItems As Outlook.Items, objRItems As Outlook.Items

Set objItems = ContactFolder.Items
Set objRItems = objItems.Restrict("[E-mail] = '" & email & "'")

If objRItems.Count = 0 Then Exit Function
Set GetContactByEmailAddress = objRItems.Item(1)
End Function

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


" wrote:

Hello,

I need to programatically access some information about a sender of an
email in Outlook.

In Outlook itself, I can rigth-click on the message sender, click Add
to Contacts, and then, when I open this contact up from Contacts, I
have not only his name and email, but his phone number, company,
department, etc. and other info recieved through Exchange or some
header.

Well, I need that information and it seems that MailItem only provides
me access to SenderName and SenderEmailAddress.

Is there any way I can programmatically access that information i.e. is
their a DOM way to retrieve the info that you can get by the manual
method described above?

Thanks in advance,
elenev


Ads