CMailMessage::ParseAddress Method  
 
INT ParseAddress(
  LPCTSTR lpszString,  
  LPCTSTR lpszDomain,  
  LPTSTR lpszAddress,  
  INT nMaxLength  
);
INT ParseAddress(
  LPCTSTR lpszString,  
  LPTSTR lpszAddress,  
  INT nMaxLength  
);
INT ParseAddress(
  LPCTSTR lpszString,  
  CString& strAddress  
);

The ParseAddress method parses a string for an email address, copying the address to the specified buffer.

Parameters

lpszString
A null-terminated string which contains the email address to parse.
lpszDomain
A null-terminated string which specifies a default domain for the address. This parameter may be NULL or point to an empty string if no default domain is required.
lpszAddress
A null-terminated string buffer which will contain the parsed email address when the method returns. It is recommended that this buffer be at least 128 characters in length.
nMaxLength
The maximum number of characters which can be copied into the string buffer, including the terminating null character.

Return Value

If the method succeeds, the return value is the length of the address. If the method fails, the return value is MIME_ERROR. To get extended error information, call GetLastError.

Remarks

The ParseAddress method is useful for parsing the email addresses that may be specified in various header fields in the message. In many cases, the addresses have additional comment characters which are not part of the address itself. For example, one common format used is as follows:

"User Name" <user@domain.com>

In this case, the email address is enclosed in angle brackets and the name outside of the brackets is considered to be a comment which is not part of the address itself. Another common format is:

user@domain.com (User Name)

In this case, there is the address followed by a comment which is enclosed in parenthesis. The ParseAddress method recognizes both formats, and when passed either string, would return the following address:

user@domain.com

If there was no domain specified in the address, that is just a user name was specified, then the value the lpszDomain parameter is added to the address.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csmsgv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also