CSmtpClient::SendMessage Method  
 
INT SendMessage(
  LPCTSTR lpszFrom,  
  LPCTSTR lpszRecipient,  
  LPCTSTR lpszFileName  
);
INT SendMessage(
  LPCTSTR lpszFrom,  
  LPCTSTR lpszRecipient,  
  LPBYTE lpMessage,  
  DWORD dwMessageSize  
);
INT SendMessage(
  LPCTSTR lpszFrom,  
  LPCTSTR lpszRecipient,  
  HGLOBAL hgblMessage,  
  DWORD dwMessageSize  
);

The SendMessage method sends the contents of a file or buffer to the specified recipients.

Parameters

lpszFrom
Pointer to a string which specifies the email address of the sender.
lpszRecipient
Pointer to a string which specifies the recipient of the message. Multiple recipients may be specified by separating each address with a comma.
lpszFileName
Pointer to a string which specifies a file that contains the message to be delivered.
lpMessage
Pointer to a buffer which contains the message to be delivered. This may also be a global memory handle which references the message data.
dwMessageSize
An unsigned integer which specifies the length of the message in bytes.

Return Value

If the method succeeds, the return value is the result code from the server. If the method fails, the return value is SMTP_ERROR. To get extended error information, call GetLastError.

Remarks

The SendMessage method is used to send the contents of a file, buffer or global memory handle to the specified recipients. The message must be in the standard format as described in RFC 822. The CMailMessage class can be used to compose and export a message in the correct format.

This protocol is only concerned with the delivery of a message and not its contents. Header fields in the message are not parsed to determine the recipients. This recipient parameter should be a concatenation of all recipients, including carbon copies and blind carbon copies, with each address separated with a comma.

This method will cause the current thread to block until the complete message has been delivered, a timeout occurs or the operation is canceled. During the transfer, the SMTP_EVENT_PROGRESS event will be periodically fired, enabling the application to update any user interface controls. Event notification must be enabled, either by calling EnableEvents, or by registering a callback function using the RegisterEvent method.

To determine the current status of the transaction while it is in progress, use the GetTransferStatus method.

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

AppendMessage, CloseMessage, GetTransferStatus, SubmitMessage