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:

Sending File Attachments

To add attachments to an outgoing message:

  1. Prepare a variable of type MAPIMessage to represent the message (as already described in this chapter).

  2. Set the FileCount member of the MAPIMessage variable equal to the desired number of attachments.

  3. Dimension an array of MapiFile elements with as many elements as there are files to attach.

  4. Set the member values of each array element.

  5. Pass the array to the MAPISendMail function.

Example 3-3 shows a code fragment that sends a single file attachment to a single recipient. 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. The message thus sent, when viewed in Microsoft Outlook 98, is shown in Figure 3-3.

Example 3-3. Sending a File Attachment

Dim nRetVal As Long Dim MyMessage As MAPIMessage Dim MyRecips( ) As MapiRecip Dim MyFiles( ) As MapiFile ' Set the subject and body text. MyMessage.Subject = "Test message from Simple MAPI, with attachment." MyMessage.NoteText = "This is the body text of the message." ' Add a recipient. MyMessage.RecipCount = 1 ReDim MyRecips(1 To MyMessage.RecipCount) As MapiRecip nRetVal = MAPIResolveName(nMAPISession, 0, "Annemarie", 0, 0, MyRecips(1)) ' Add an attachment. MyMessage.FileCount = 1 ReDim MyFiles(1 To MyMessage.FileCount) As MapiFile MyFiles(1).PathName = "c:\autoexec.bat" ' Send the message. nRetVal = MAPISendMail(nMAPISession, 0, MyMessage, MyRecips, MyFiles, ...
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