Reading File Attachments

Attachments are retrieved from the message store and copied to temporary local files automatically when messages are read. After a call to BMAPIGetReadMail, attachment information appears in the array passed to that function’s File parameter. Have another look at the BMAPIGetReadMail call from Example 3-4:

' Read the fetched message.
nRetVal = BMAPIGetReadMail(nMsg, MyMessage, MyRecips, MyFiles, _
   recipOriginator)

Just prior to this call in Example 3-4, the MyFiles array was dimensioned to have as many elements as there are attachments to the email. The BMAPIGetReadMail call then fills each element with information about the corresponding attachment. Each element holds a MapiFile user-defined type, shown earlier in this chapter and repeated here:

Type MapiFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As String
End Type

The usage of each member is the same as that described in Section 3.4 earlier in this chapter.

What you do with this information depends on your application’s requirements. One option would be to allow the user to copy an attachment from an email to a disk file. Because email attachments are stored as temporary files when the email is fetched, this feature can be implemented simply by calling Visual Basic’s FileCopy statement to copy the file from its temporary location to a destination specified by the user. Assuming that MyFiles is defined as in Example 3-4, that BMAPIGetReadMail has been ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.