MailBee.NET Objects 3.1

Smtp.GetSupportedAuthMethods Method 

Returns a set of flags indicating which authentication methods are supported by the server.

public AuthenticationMethods GetSupportedAuthMethods();

Return Value

A set of flags indicating which authentication methods are supported by the server, or None if Hello method has not yet been called or if the server does not support EHLO command (i.e. the server is not ESMTP enabled).

Exceptions

Exception Type Condition
MailBeeInvalidStateException There are multiple or non-SMTP connections being opened at the moment (IsSmtpContext is false).

Example

This sample lists all authentication methods supported by the SMTP server. SMTP servers do not support non-SASL methods, thus only SASL methods are checked.

[C#]
// To use the code below, import these namespaces at the top of your code.
using System;
using MailBee;
using MailBee.SmtpMail;

// The actual code (put it into a method of your class)

Smtp mailer = new Smtp();
mailer.SmtpServers.Add("mail.domain.com");
mailer.Connect();
mailer.Hello();

AuthenticationMethods methods = mailer.GetSupportedAuthMethods();
if ( (methods & AuthenticationMethods.SaslLogin) > 0)
{
    Console.WriteLine("SASL LOGIN");
}
if ( (methods & AuthenticationMethods.SaslPlain) > 0)
{
    Console.WriteLine("SASL PLAIN");
}
if ( (methods & AuthenticationMethods.SaslCramMD5) > 0)
{
    Console.WriteLine("SASL CRAM-MD5 (secure)");
}

mailer.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.SmtpMail

' The actual code (put it into a method of your class)

Dim mailer = New Smtp
mailer.SmtpServers.Add("mail.domain.com")
mailer.Connect()
mailer.Hello()

Dim methods As AuthenticationMethods = mailer.GetSupportedAuthMethods()
If ((methods And AuthenticationMethods.SaslLogin) > 0) Then
    Console.WriteLine("SASL LOGIN")
End If
If ((methods And AuthenticationMethods.SaslPlain) > 0) Then
    Console.WriteLine("SASL PLAIN")
End If
If ((methods And AuthenticationMethods.SaslCramMD5) > 0) Then
    Console.WriteLine("SASL CRAM-MD5 (secure)")
End If

mailer.Disconnect()

See Also

Smtp Class | MailBee.SmtpMail Namespace | GetExtensions