Smtp Capabilities Class
The set of capabilities supported by an SMTP server.
Definition
Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public sealed class SmtpCapabilities : IReadOnlyCollection<SmtpCapability>,
IEnumerable<SmtpCapability>, IEnumerable- Inheritance
- Object SmtpCapabilities
Remarks
Capabilities are read as part of the response to the EHLO command that is issued during the connection and authentication phases of the SmtpClient.
The capabilities can be accessed in two ways:
- As a set of well-known SmtpCapability values that MailKit understands and makes use of. This is the recommended way of checking whether the server supports a particular feature (see Contains(SmtpCapability)).
- As the raw list of extension keywords that the server advertised, including any that MailKit does not know about (see Names, Contains(String) and GetValues(String)). This is useful for checking support for extensions that do not (yet) have a corresponding SmtpCapability value.
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);
}
}
Constructors
| SmtpCapabilities | Initialize a new instance of the SmtpCapabilities class. |
Properties
| Count | Get the number of well-known capabilities in the set. |
| Names | Get the raw extension keywords advertised by the server. |
Methods
| Contains(SmtpCapability) | Check whether the set contains the specified well-known capability. |
| Contains(String) | Check whether the server advertised the specified extension keyword. |
| Disable | Disable the specified well-known capability. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| GetEnumerator | Get an enumerator for the well-known capabilities in the set. |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| GetValues | Get the values advertised for the specified extension keyword. |
| ToString |
Get a string representation of the well-known capabilities in the set.
(Overrides ObjectToString) |