CSmtpClient::SubmitMessage Method  
 
BOOL SubmitMessage(
  LPSMTPSERVER lpServer,  
  LPSMTPMESSAGE lpMessage,  
  SMTPEVENTPROC lpEventProc,  
  DWORD_PTR dwParam  
);
BOOL SubmitMessage(
  LPSMTPSERVER lpServer,  
  LPSMTPMESSAGEEX lpMessage,  
  SMTPEVENTPROC lpEventProc,  
  DWORD_PTR dwParam  
);

The SubmitMessage method composes and submits a message for delivery to the specified mail server.

Parameters

lpServer
A pointer to an SMTPSERVER structure that contains information about the mail server that the message will be submitted to for delivery. This parameter cannot be NULL and the structure members must be properly initialized prior to calling this function.
lpMessage
A pointer to an SMTPMESSAGE or SMTPMESSAGEEX structure that contains information about the message, including the sender, recipients and the body of the message. This parameter cannot be NULL and the structure members must be property initialized prior to calling this function.
lpEventProc
An optional pointer to the procedure-instance address of an application defined callback function. For more information about event handling and the callback function, see the description of the SmtpEventProc callback function. If this parameter is NULL or is omitted, event notification is disabled.
dwParam
An optional user-defined integer value that is passed to the callback function. If the lpEventProc parameter is NULL, this value should be zero.

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 SmtpGetLastError.

Remarks

The SubmitMessage method provides a high-level interface that enables an application to send an email message with a single function call. The SMTPSERVER and SMTPMESSAGE structures are used to provide the function with information about the mail server that will accept the message and the contents of the message itself. Note that this method does not require you to call the Connect method prior to calling this function.

If you need to specify additional custom headers in the message that is submitted for delivery, you should use the SMTPMESSAGEEX structure. It is an extended version of the message structure which will allow you to define custom headers to be included in the message.

This method will cause the calling thread to block until the message has been submitted for delivery, an error occurs or the connection to the mail server times out. If an event handler is specified, then the callback function will be periodically invoked as the message is being sent. For large messages, the SMTP_EVENT_PROGRESS event can be used to monitor the submission process and update the user interface. The GetTransferStatus method can be used within the callback function to obtain information about the current status of the submission.

Example

CSmtpClient smtpClient;

SMTPSERVER mailServer;
ZeroMemory(&mailServer, sizeof(mailServer));
mailServer.lpszHostName = _T("smtp.gmail.com");
mailServer.nHostPort = SMTP_PORT_SUBMIT;
mailServer.lpszUserName = m_strSender;
mailServer.lpszPassword = m_strPassword;
mailServer.dwOptions = SMTP_OPTION_SECURE;

SMTPMESSAGE mailMessage;
ZeroMemory(&mailMessage, sizeof(mailMessage));
mailMessage.lpszFrom = m_strSender;
mailMessage.lpszTo = m_strRecipients;
mailMessage.lpszSubject = m_strSubject;
mailMessage.lpszText = m_strMessage;

if (smtpClient.SubmitMessage(&mailServer, &mailMessage))
    _tprintf(_T("SubmitMessage was successful\n"));
else
{
    CString strError;
    smtpClient.GetErrorString(strError);
    _tprintf(_T("SubmitMessage failed: %s\n"), strError);
}

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

SendMessage, SmtpEventProc, SMTPMESSAGE, SMTPMESSAGEEX, SMTPSERVER