Skip to Content
CDO & MAPI Programming with Visual Basic:
book

CDO & MAPI Programming with Visual Basic:

by Dave Grundgeiger
October 2000
Intermediate to advanced
384 pages
10h 22m
English
O'Reilly Media, Inc.
Content preview from CDO & MAPI Programming with Visual Basic:

Reading Mail

Three API functions are related to reading messages. Each one handles a different aspect of the process, and all three must be used to retrieve incoming messages successfully. These functions are:

MAPIFindNext

Iterates through the messages in the user’s Inbox, returning a message ID for each message.

BMAPIReadMail

Fetches a message to the local machine, given the message ID returned from MAPIFindNext.

BMAPIGetReadMail

Reads a fetched message.

The code in Example 3-4 loops through the messages in the user’s Inbox and prints the subject text of each message to the Visual Basic Immediate window. This code assumes that a session has already been established via a call to the MAPILogon function, and that the session handle is held in a variable called nMAPISession.

Example 3-4. Reading Messages

Dim nRetVal As Long Dim nRetValFindNext As Long Dim strSeedMessageID As String Dim strMessageID As String Dim nMsg As Long Dim MyMessage As MAPIMessage ReDim MyRecips(0 To 0) As MapiRecip ReDim MyFiles(0 To 0) As MapiFile Dim recipOriginator As MapiRecip Dim nRecipients As Long Dim nFiles As Long ' This tells MAPIFindNext to start with the first message. strSeedMessageID = "" Do ' for each message in the user's Inbox ' Get the next message ID. strMessageID = String(512, 0) nRetValFindNext = MAPIFindNext(nMAPISession, 0, "", _ strSeedMessageID, 0, 0, strMessageID) ' if there was another message If nRetValFindNext = SUCCESS_SUCCESS Then ' Fetch message associated with the message ID. nRetVal ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
COM Programming with Microsoft® .NET

COM Programming with Microsoft® .NET

John Paul Mueller, Julian Templeman

Publisher Resources

ISBN: 156592665XSupplemental ContentCatalog PageErrata