CMailMessage::ExtractFile Method  
 
BOOL ExtractFile(
  INT nMessagePart,  
  LPCTSTR lpszFileName  
);
BOOL ExtractFile(
  LPCTSTR lpszAttachment,  
  LPCTSTR lpszFileName  
);
BOOL ExtractFile(
  LPCTSTR lpszFileName  
);

The ExtractFile method extracts a file attachment from the message and stores it on the local system.

Parameters

nMessagePart
An integer value that specifies the message part that contains the file attachment. This value may be -1, in which case the current message part will be used.
lpszAttachment
A pointer to a string that specifies the file name for the attachment in the message. If the file name of the attachment is not known, this parameter can be NULL or point to an empty string.
lpszFileName
A pointer to a string that specifies the name of a file on the local system. If this parameter is NULL or points to an empty string, the value of the lpszAttachment parameter will specify the name of the file in the current working directory. If both the lpszAttachment and lpszFileName parameters are NULL, the method will fail.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This method will store the contents of a file attachment in the current message part to the specified file on the local system. If a path is specified as part of the file name, it must exist and the current user must have the appropriate permissions to create the file. If a file with the same name already exists, it will be overwritten with the contents of the attachment. If the file attachment was encoded using base64 or uuencode, this method will automatically decode the contents of the attachment.

If the nMessagePart parameter is specified, then an attachment in that message part will be stored in the specified file. If the message part does not contain a file attachment, the method will fail.

If the lpszAttachment parameter is specified, the method will search the entire message for an attachment with the same file name. The search is not case-sensitive, however it must match the attachment file name completely. This method will not match partial file names or names that include wildcard characters. If a match is found, the contents of that attachment will be stored in the file specified by the lpszFileName parameter.

To extract all of the files attached to a message in a single method call, use the ExtractAllFiles method.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csmsgv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

AttachFile, EnumAttachments, ExportMessage, ExtractAllFiles, ImportMessage