CMailMessage::GetAllRecipients Method  
 
INT GetAllRecipients(
  LPCTSTR lpszExtraAddress,  
  LPTSTR lpszRecipients,  
  INT nMaxLength  
);
INT GetAllRecipients(
  CString& strRecipients,  
  LPCTSTR lpszExtraAddress  
);

The GetAllRecipients method returns a comma-separated list of recipient addresses in a string buffer.

Parameters

lpszExtraAddress
A pointer to a string which contains one or more additional email addresses that should be included in the list, in addition to those found in the message. If more than one address is specified, each address should be separated by a comma. This parameter may be NULL if there are no extra addresses to include in the recipient list.
lpszRecipients
Pointer to string buffer which will contain a comma-separated list of email addresses when the method returns. This parameter may be NULL, in which case the method will calculate the number of characters needed to store the complete list.
nMaxLength
An integer value which specifies the maximum number of characters that can be stored in the lpszRecipients string. If the lpszRecipients parameter is NULL, this value must be zero. If the lpszRecipients parameter is not NULL, this value must be large enough to store the entire list of addresses.

Return Value

If the method succeeds and the lpszRecipients parameter is NULL, the return value is the minimum number of characters that should be allocated to store the list recipient addresses, including the terminating null character. If the lpszRecipients parameter is not NULL, then the return value is the number of characters copied into the buffer, not including the terminating null character. If the method returns a value of zero, then the specified message has no recipients. If the method fails, the return value is MIME_ERROR. To get extended error information, call GetLastError.

Remarks

The GetAllRecipients method is useful for creating a list of message recipients that can be passed to methods like CSmtpClient::SendMessage. If you wish to dynamically allocate the string buffer that will contain the list of recipients, then the lpszRecipients parameter should be NULL and the nMaxLength parameter should have a value of zero. The method will then return the recommended size of the buffer that should be allocated. This value is guaranteed to be large enough to store the entire list of message recipients, including the terminating null character.

Example

CString strRecipients;

if (pMessage->GetAllRecipients(strRecipients) < 1)
{
    // There are no recipients for the current message  
    AfxMessageBox(IDS_ERROR_NO_RECIPIENTS);
    return;
}

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

EnumRecipients, GetFirstHeader, GetHeader, GetNextHeader, SetHeader