CMailMessage::AttachData Method  
 
BOOL AttachData(
  LPBYTE lpBuffer,  
  LONG cbBuffer,  
  LPCTSTR lpszContentName,  
  LPCTSTR lpszContentType,  
  DWORD dwOptions  
);
BOOL AttachData(
  CString& strBuffer,  
  LPCTSTR lpszContentName,  
  LPCTSTR lpszContentType,  
  DWORD dwOptions  
);

The AttachData method attaches the contents of the buffer to the message.

Parameters

lpBuffer
Pointer to a byte buffer which contains the data to be attached to the message. This parameter may be NULL, in which case no data is attached, but an additional empty message part will be created. An alternate form of this method accepts a CString object which contains the text to be attached to the message.
cbBuffer
An unsigned integer which specifies the number of bytes of data in the buffer pointed to by the lpBuffer parameter. If the lpBuffer parameter is NULL, this value must be zero.
lpszContentName
Pointer to a string which specifies a name for the data being attached to the message. This typically is used as a file name by the mail client to store the data in. If this parameter is NULL or an empty string then no name is defined and the data is attached as inline content. Note that if a file name is specified with a path, only the base name will be used.
lpszContentType
Pointer to a string which specifies the type of data being attached. The value must be a valid MIME content type. If this parameter is NULL or an empty string, then the buffer will be examined to determine what kind of data it contains. If there is only text characters, then the content type will be specified as "text/plain". If the buffer contains binary data, then the content type will be specified as "application/octet-stream", which is appropriate for any type of data.
dwOptions
A value which specifies one or more options. This parameter is constructed by using a bitwise operator with any of the following values:
Constant Description
MIME_ATTACH_DEFAULT The data encoding is based on the content type. Text data is not encoded, and binary data is encoded using the standard base64 encoding algorithm.
MIME_ATTACH_BASE64 The data is always encoded using the standard base64 algorithm, even if the buffer only contains printable text characters.
MIME_ATTACH_UUCODE The data is always encoded using the uuencode algorithm, even if the buffer only contains printable text characters.
MIME_ATTACH_QUOTED The data is always encoded using the quoted-printable algorithm. This encoding should only be used if the data contains 8-bit text characters.

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

The AttachData method allows an application to attach data to the message as either a file attachment or as inline content. The recipient of the message will see the attached data in the same way that they would see a file attached to the message using the AttachFile method.

If the specified message is not a multipart message, it is marked as multipart and the attached file is appended to the message. If the message is already a multipart message, an additional part is created and the attachment is added to the message.

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, ExportMessage, ExtractFile, GetAttachedFileName, GetFileContentType, ImportMessage, SetFileContentType