Mailbox AddressParse(String) Method
Parse the given text into a new MailboxAddress instance.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The parsed MailboxAddress.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static MailboxAddress Parse(
string text
)Parameters
- text String
- The text.
Return Value
MailboxAddressThe parsed MailboxAddress.
Remarks
Parses a single MailboxAddress. If the address is not a mailbox address or
there is more than a single mailbox address, then parsing will fail.
Example
C#
public static void ParseMailbox ()
{
// Parse() throws a ParseException if the text is not a valid mailbox address.
var mailbox = MailboxAddress.Parse ("\"Bing, Chandler\" <chandler@friends.com>");
Console.WriteLine ("Name: {0}", mailbox.Name); // Bing, Chandler
Console.WriteLine ("Address: {0}", mailbox.Address); // chandler@friends.com
Console.WriteLine ("LocalPart: {0}", mailbox.LocalPart); // chandler
Console.WriteLine ("Domain: {0}", mailbox.Domain); // friends.com
// ToString() quotes the name if needed. Passing true for the encode argument also
// rfc2047-encodes any non-ASCII characters, making the result suitable for use in
// a message header.
Console.WriteLine (mailbox.ToString (true)); // "Bing, Chandler" <chandler@friends.com>
}
Exceptions
| ArgumentNullException | text is . |
| ParseException | text could not be parsed. |