HOWTO: Retrieve MAPI User Information with OLE Messaging

Last reviewed: December 22, 1997
Article ID: Q154514
The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Collaboration Data Objects (CDO), versions 1.1 and 1.2

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

  1. Start a new project. Form1 is created by default.

  2. Place a CommandButton on Form1.

  3. 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
    
    

  4. 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.

REFERENCES

OLE Messaging is fully documented in the Win32 SDK, available on the Microsoft Developer Network (MSDN).

The Mastering Series for Exchange Development, also available from Microsoft, has extensive Visual Basic code samples and explanations relating to OLE Messaging.

For additional information about Collaboration Data Objects versus Active Messaging, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q176916
   TITLE     : INFO: Active Messaging and Collaboration Data Objects (CDO)

Keywords          : VB4WIN vb5all vb5howto vb4all kbhowto
Technology        : kbole
Version           : 4.0 5.0
Platform          : NT WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.