Microsoft KB Archive/154514

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0
 * Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0
 * Collaboration Data Objects (CDO), versions 1.1, 1.2, 1.21

-

SUMMARY
The OLE Messaging Library can be used to gain access to MAPI address book information. This article provides a simple example that shows how to retrieve details of a mail user via the OLE Messaging interface.

MORE INFORMATION
The Microsoft OLE Messaging Library exposes messaging objects for use by Microsoft Visual Basic and Microsoft Visual C++ applications. The Microsoft OLE Messaging Library does not represent a new messaging model. It represents an additional interface to the Messaging Application Programming Interface (MAPI) model, designed to handle the most common tasks for client developers using Visual Basic and Visual C++.

To use the example in this article, you will need to have a MAPI-compliant mail system installed and the OLE Messaging Library that comes with Microsoft Exchange 4.0 or later and also as part of the Microsoft Developer Network.

Step-by Step Example
 Start a new project. Form1 is created by default. Place a CommandButton on Form1.  Add the following code to the General Declarations section of Form1:      Option Explicit

Private Const PR_BUSINESS_TELEPHONE_NUMBER As Long = &H3A08001E Private Const PR_OFFICE_LOCATION As Long = &H3A19001E Private Const PR_DEPARTMENT_NAME As Long = &H3A18001E Private Const PR_COMPANY_NAME As Long = &H3A16001E

Sub Show_Details(sUserEmailName As String) Dim objsession As Object Dim objMessage As Object Dim objUser As Object Dim objOneRecip As Object Dim addrentry As Object Screen.MousePointer = vbHourglass Set objsession = CreateObject("MAPI.Session") objsession.Logon Set objMessage = objsession.Outbox.Messages.Add Set objOneRecip = objMessage.Recipients.Add objOneRecip.Name = sUserEmailName objOneRecip.Type = 1 objOneRecip.Resolve Set addrentry = objOneRecip.addressentry With addrentry.Fields Print "Phone: " & .Item(PR_BUSINESS_TELEPHONE_NUMBER).Value Print "Office: " & .Item(PR_OFFICE_LOCATION).Value Print "Full Name: " & objOneRecip.Name Print "Department: " & .Item(PR_DEPARTMENT_NAME).Value Print "Company:" & .Item(PR_COMPANY_NAME).Value End With Screen.MousePointer = vbArrow End Sub

Private Sub Command1_Click Show_Details "Johndoe" End Sub  Press the F5 key to run the project. The information for the specified user will be printed on the form. The sUserEmailName parameter in the Show_Details routine can be the full name or the alias for the user.