CMailMessage::GetSender Method  
 
INT GetSender(
  LPCTSTR lpszSender,  
  INT nMaxLength  
);
INT GetSender(
  CString& strSender  
);

The GetSender method returns the email address of the message sender in the specified string buffer.

Parameters

lpszSender
A pointer to a string buffer that will contain the email address of the message sender when the method returns. In alternate forms of this method, a CString object may be specified which will contain the email address when the method returns.
nMaxLength
An integer value that specifies the maximum number of characters that can be copied to the string buffer, including the terminating null character. It is recommended that the maximum length be at least 64 characters.

Return Value

If the method succeeds, the return value is the number of bytes copied to the string buffer. If an error occurs, the method will return MIME_ERROR. To get extended error information, call GetLastError.

Remarks

This method attempts to determine the email address of the sender that originated the message. It will first check for the presence of a Sender or X-Sender header value. If these headers are not defined, it will use the value of the From header field. It will only return successfully if a valid email address can be found.

If the method succeeds, the string buffer that is provided will only contain an email address. It will not contain the display name of the user associated with the address or any extraneous comments that are included in quotes or parenthesis.

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

EnumHeaders, GetFirstHeader, GetHeader, GetPart, GetNextHeader, ParseHeader, SetHeader, SetPart