SmtpClientAuthenticationMechanisms Property

Get the authentication mechanisms supported by the SMTP server.

Definition

Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public override HashSet<string> AuthenticationMechanisms { get; }

Property Value

HashSetString
The authentication mechanisms.

Implements

IMailServiceAuthenticationMechanisms
IMailServiceAuthenticationMechanisms

Remarks

The authentication mechanisms are queried as part of the connection process.

  Tip

To prevent the usage of certain authentication mechanisms, simply remove them from the AuthenticationMechanisms hash set before authenticating.

Example

C#
                    public static void PrintCapabilities ()
{
    using (var client = new SmtpClient ()) {
        client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);

        if (client.Capabilities.Contains (SmtpCapability.Authentication)) {
            var mechanisms = string.Join (", ", client.AuthenticationMechanisms);
            Console.WriteLine ("The SMTP server supports the following SASL mechanisms: {0}", mechanisms);
            client.Authenticate ("username", "password");
        }

        if (client.Capabilities.Contains (SmtpCapability.Size))
            Console.WriteLine ("The SMTP server has a size restriction on messages: {0}.", client.MaxSize);

        if (client.Capabilities.Contains (SmtpCapability.Dsn))
            Console.WriteLine ("The SMTP server supports delivery-status notifications.");

        if (client.Capabilities.Contains (SmtpCapability.EightBitMime))
            Console.WriteLine ("The SMTP server supports Content-Transfer-Encoding: 8bit");

        if (client.Capabilities.Contains (SmtpCapability.BinaryMime))
            Console.WriteLine ("The SMTP server supports Content-Transfer-Encoding: binary");

        if (client.Capabilities.Contains (SmtpCapability.UTF8))
            Console.WriteLine ("The SMTP server supports UTF-8 in message headers.");

        client.Disconnect (true);
    }
}
                  

See Also