CSmtpClient::Write Method  
 
INT Write(
  LPBYTE lpBuffer,  
  INT cbBuffer  
);
INT Write(
  LPCTSTR lpszBuffer  
  INT cbBuffer  
);

The Write method sends the specified number of bytes to the server.

Parameters

lpBuffer
The pointer to the buffer which contains the data that is to be sent to the server. In an alternate form of the method, the pointer is to a string.
cbBuffer
The number of bytes to send from the specified buffer. This value must be greater than zero, unless a pointer to a string buffer is passed as the parameter. In that case, if the value is -1, all of the characters in the string, up to but not including the terminating null character, will be sent to the server.

Return Value

If the method succeeds, the return value is the number of bytes actually written. If the method fails, the return value is SMTP_ERROR. To get extended error information, call GetLastError.

Remarks

The return value may be less than the number of bytes specified by the cbBuffer parameter. In this case, the data has been partially written and it is the responsibility of the client application to send the remaining data at some later point. For non-blocking clients, the client must wait for the next asynchronous notification message before it resumes sending data.

If the Write method is used to send the message contents to the server, the application must first call the CreateMessage method to specify the sender and the length of the message, followed by one or more calls to the AddRecipient method to specify each recipient of the message. When all of the message text has been submitted to the server, the application must call the CloseMessage method.

The message text is filtered by the Write method, and it will automatically normalize end-of-line character sequences to ensure the message meets the protocol requirements. The message itself must be in a standard RFC 822 or multi-part MIME message format, or the server may reject the message. Binary data, such as file attachments, should always be encoded. The CMailMessage class can be used to compose and export a message in the correct format, which can then be submitted to the server.

It is recommended that most applications use the SendMessage method to submit the message for delivery.

An alternative approach to creating a message without using the CMailMessage class is the SubmitMessage method. It accepts two structure parameters which define the message contents and the connection information for the mail server. This enables the application to compose the message and submit it for delivery in a single method call.

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, CreateMessage, SendMessage, SubmitMessage