CSmtpClient::CreateMessage Method  
 
INT CreateMessage(
  LPCTSTR lpszSender,  
  DWORD dwMessageSize  
);

The CreateMessage method creates a new message for delivery.

Parameters

lpszSender
A pointer to a string which specifies the email address of the user sending the message. This typically corresponds to the address in the From header of the message, but it is not required that they be the same.
dwMessageSize
An unsigned integer which specifies the size of the message in bytes. If the size of the message is unknown, this value should be zero. This parameter is ignored if the server does not support extended features. If the message size is larger than what the server will accept, this method will fail. Most Internet Service Providers impose a limit on the size of an email message, typically between 5 and 10 megabytes.

Return Value

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

Remarks

The CreateMessage method begins the composition of a new message to be submitted to the mail server for delivery. There are several steps that must be followed when dynamically composing a message for delivery:

  1. Call the CreateMessage method to begin the message composition. The sender email address should generally be the same address as the one used in the "From" header field in the message.
  2. Call the AddRecipient method for each recipient of the message. These addresses are typically specified in the "To" and "Cc" header fields in the message. Additional addresses may also be be provided which are not specified in the email message itself. This is how one or more blind carbon copies of a message is delivered. Most servers have a limit on the total number of recipients that may be specified for a single message. This limit is usually around 100 addresses.
  3. Call the Write method to write the contents of the message to the data stream. The application may also choose to use the AppendMessage method to write out a large amount of message data, or write the contents of a file to the data stream.
  4. Call the CloseMessage method to close the message and submit it to the mail server for delivery.

For applications that do not need to dynamically compose the message and already have the message contents stored in a file or memory buffer, the SendMessage method is the preferred method of submitting a message for delivery.

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: csmtpv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

AddRecipient, AppendMessage, CloseMessage, SendMessage, Write