MailboxAddressGetAddress Method

Get the mailbox address, either IDN-encoded or decoded.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public string GetAddress(
	bool idnEncode
)

Parameters

idnEncode  Boolean
if the address should be encoded according to IDN encoding rules; otherwise, to decode it.

Return Value

String
The mailbox address.

Remarks

If idnEncode is , then each internationalized label of the domain is encoded as an A-label (e.g. user@xn--bcher-kva.example). Otherwise, each A-label of the domain is decoded into its Unicode form (e.g. user@bücher.example).

The local-part and domain literals (e.g. [127.0.0.1]) are always returned as-is. To get the address exactly as it was parsed or set, use Address.

Example

C#
                    public static void PrintInternationalAddress ()
{
    var mailbox = new MailboxAddress ("Jörg Müller", "jörg@bücher.example");

    // An address is international if the local-part or domain contain non-ASCII characters.
    Console.WriteLine ("IsInternational: {0}", mailbox.IsInternational); // True

    // GetAddress (true) converts the domain into its ASCII-compatible (punycode) form.
    Console.WriteLine (mailbox.GetAddress (true)); // jörg@xn--bcher-kva.example

    // When encoding for use in a message header, the name is rfc2047-encoded and the domain
    // is punycode-encoded. If the SMTP server supports the SMTPUTF8 extension, enable the
    // FormatOptions.International option in order to leave the UTF-8 text as-is.
    var options = FormatOptions.Default.Clone ();
    options.International = true;

    // =?utf-8?b?SsO2cmcgTcO8bGxlcg==?= <jörg@xn--bcher-kva.example>
    Console.WriteLine (mailbox.ToString (FormatOptions.Default, true));

    // Jörg Müller <jörg@bücher.example>
    Console.WriteLine (mailbox.ToString (options, true));
}
                  

See Also