CMailMessage::ExportMessage Method  
 
BOOL ExportMessage(
  LPCTSTR lpszFileName,  
  DWORD dwExportOptions  
);
BOOL ExportMessage(
  HGLOBAL *lphBuffer,  
  LPDWORD lpdwBufferSize,  
  DWORD dwExportOptions  
);
BOOL ExportMessage(
  LPTSTR lpszMessage,  
  DWORD dwMessageSize,  
  DWORD dwExportOptions  
);
BOOL ExportMessage(
  CString& strMessage,  
  DWORD dwExportOptions  
);

The ExportMessage method exports the message to a file, the system clipboard or global memory buffer.

Parameters

lpszFileName
A pointer to a string which specifies the file name that will contain the message. If the file already exists, it will be overwritten with the message contents.
lpszMessage
A pointer to a string which will contain the message. An alternate form of this method accepts a pointer to a global memory handle which will contain the message data when the method returns.
dwMessageSize
An unsigned integer value which specifies the maximum size of the lpszMessage buffer.
dwExportOptions
An unsigned integer which specifies how the message will be exported. The following values may be combined using a bitwise Or operator:
Value Description
MIME_OPTION_DEFAULT The default export options. The headers for the message are written out in a specific consistent order, with custom headers written to the end of the header block regardless of the order in which they were set or imported from another message. If the message contains Bcc, Received, Return-Path, Status or X400-Received header fields, they will not be exported.
MIME_OPTION_KEEPORDER The original order in which the message header fields were set or imported are preserved when the message is exported.
MIME_OPTION_ALLHEADERS All headers, including the Received, Return-Path, Status and X400-Received header fields will be exported. Normally these headers are not exported because they are only used by the mail transport system. This option can be useful when exporting a message to be stored on the local system, but should not be used when exporting a message to be delivered to another user.
MIME_OPTION_NOHEADERS When exporting a message, the main header block will not be included. This can be useful when creating a multipart message for services which expect MIME formatted data, such as HTTP POST requests. This option should never be used for email messages being submitted using SMTP.

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

If the version of this method is used which exports the message to a pre-allocated string buffer, the dwMessageSize parameter must specify the maximum size of the buffer. If the method succeeds, the message will be copied to the buffer. If the method fails, the previous contents of the buffer will not be preserved. If the buffer provided is not large enough to store the entire message, the message contents will be truncated. The GetMessageSize method can be used to determine the minimum size of the buffer required to store the complete message.

If the version of this method is used which returns an HGLOBAL memory handle to the caller, the handle must be dereferenced using the GlobalLock function. No changes should be made to this copy of the message. If you wish to modify the contents of the message, allocate a local buffer and make a copy of the message contents, or use the method which exports the message to a pre-allocated string buffer. Your application is responsible for calling GlobalUnlock and GlobalFree to unlock and free the handle when it is no longer needed.

Example

// Exports the message contents to a global buffer
HGLOBAL hgblMessage = NULL;
DWORD dwMessageSize = 0;

if (pMessage->Export(&hgblMessage, &dwMessageSize))
{
    LPBYTE lpMessage = (LPBYTE)GlobalLock(hgblMessage);

    if (lpMessage)
    {
        // Process the contents of the message
    }

    GlobalUnlock(hgblMessage);
    GlobalFree(hgblMessage);
}

Requirements

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

See Also

ImportMessage, GetMessageSize, SetExportOptions