Syntax
MAPIQueryAttachments(PathName$, FileName$, Position$)
Remarks
Retrieves information about the file attachments of the current inbound message. First use MAPIReadMail to make a message the current inbound message, then successively call MAPIQueryAttachments to enumerate the attachments of the message. MAPIQueryAttachments returns either the type of the attachment or –1 to indicate no more attachments.
MAPIReadMail automatically creates a temporary file for every attachment unless you call MAPIReadMail with the MAPI_ENVELOPE_ONLY or MAPI_SUPPRESS_ATTACH flag. The temporary files are not deleted automatically by the workgroup extensions. You must use MAPIQueryAttachments to enumerate the attachments and delete the
temporary files.
Argument | Explanation |
PathName$ | The full path of a temporary file that contains a copy of the attached file. |
FileName$ | The filename seen by the recipient. This name can differ from the filename in PathName$ if temporary files are being used. If FileName$ is empty, the filename from PathName$ is used. If the attachment is an OLE object, FileName$ contains the class name of the object; for example, "Microsoft Excel Worksheet." |
Position$ | An integer formatted as a string indicating where the attachment is placed in the message body. |
The following table lists the possible return values of the MAPIQueryAttachments function and their meanings.
Value | Name | Meaning |
0 | Attachment is a data file, not an OLE object. | |
1 | MAPI_OLE | Attachment is an embedded OLE object. |
2 | MAPI_OLE_STATIC | Attachment is a static OLE object. |
–1 | Message contains no attachments or all attachments have been queried. |
Example
The following example successively displays the filename of each attachment of the first message in the Inbox:
Sub MAIN MAPI_LOGON_UI = 1 Session = MAPILogon(0, "", "", MAPI_LOGON_UI, 0) Dim MessageID$, PathName$, MailFileName$, Position$ result = MAPIFindNext(Session, 0, "", "", 0, 0, MessageID$) result = MAPIReadMail(Session, 0, MessageID$, 0, 0) While result >= 0 result = MAPIQueryAttachments(PathName$, MailFileName$, Position$) If result >= 0 Then MsgBox MailFileName$ Kill PathName$ End If Wend result = MAPILogoff(Session, 0, 0, 0) End Sub