Previous Topic

Next Topic

Book Contents

Book Index

Home Page

Reading E-Mail from a COM Compliant Client

The basic procedure for reading mail with a client that supports COM is as follows:

The sample code below shows how to read a mail message with Microsoft Outlook 98 or 2000. Refer to the E-Mail Reader example Call Tree or the E-Mail Reader wizard (under the Wizards menu) for a thorough example of reading and sending mail from Outlook.

' Define variables for MS Outlook objects
Dim olook, olookNameSpace, olookEMailFolder, email
' Get Outlook - Outlook must be open!
Set olook = _

GetObject("","Outlook.Application")
' Get MAPI name space
Set olookNameSpace = _

olook.GetNameSpace("MAPI")
' Get the InBox Folder.
Set olookEMailFolder = _

olookNameSpace.GetDefaultFolder(6)
' Enable error handling.
On Error Resume Next
' Get the first email object.
Set email = olookEmailFolder.Items(1)
If Err.Number = 0 Then
' Read e-mail
Speak1 = CStr(email.Body)
End If

See Also

How to Send E-Mail from a Macro

Sending E-Mail with a COM Compliant Client

Sending E-Mail from a Simple Mail Client

Sending E-Mail with Microsoft CDO