Get supported server extensions (IMAP, POP3, SMTP)
Thursday, October 6th, 2011You can use SupportedExtensionsmethod to retrieve all protocol extensions supported by the server:
// C#
using (Imap client = new Imap())
{
client.ConnectSSL("imap.example.org");
client.UseBestLogin("user", "password");
Console.WriteLine("Supported extensions:");
foreach (ImapExtension extension in client.SupportedExtensions())
{
Console.WriteLine(extension.Name);
}
Console.WriteLine("Supports IDLE:");
bool supportsIdle = client.SupportedExtensions()
.Contains(ImapExtension.Idle);
Console.WriteLine(supportsIdle);
client.Close();
}
' VB.NET
Using client As New Imap()
client.ConnectSSL("imap.example.org")
client.UseBestLogin("user", "password")
Console.WriteLine("Supported extensions:")
For Each extension As ImapExtension In client.SupportedExtensions()
Console.WriteLine(extension.Name)
Next
Console.WriteLine("Supports IDLE:")
Dim supportsIdle As Boolean = client.SupportedExtensions() _
.Contains(ImapExtension.Idle)
Console.WriteLine(supportsIdle)
client.Close()
End Using
For example Gmail produces following output:
Supported extensions: IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS Supports IDLE: True
We take great care for the API to look similar for all protocols (IMAP, POP3, SMTP).
Here’s the sample for POP3:
// C#
using (Pop3 client = new Pop3())
{
client.ConnectSSL("pop3.example.org");
client.UseBestLogin("user", "password");
Console.WriteLine("Supported extensions:");
foreach (Pop3Extension extension in client.SupportedExtensions())
{
Console.WriteLine(extension.Name);
}
Console.WriteLine("Supports TOP:");
bool supportsTop= client.SupportedExtensions()
.Contains(Pop3Extension.Top);
Console.WriteLine(supportsTop);
client.Close();
}
' VB.NET
Using client As New Pop3()
client.ConnectSSL("pop3.example.org")
client.UseBestLogin("user", "password")
Console.WriteLine("Supported extensions:")
For Each extension As Pop3Extension In client.SupportedExtensions()
Console.WriteLine(extension.Name)
Next
Console.WriteLine("Supports TOP:")
Dim supportsTop As Boolean = client.SupportedExtensions() _
.Contains(Pop3Extension.Top)
Console.WriteLine(supportsTop)
client.Close()
End Using
Here’s the sample for SMTP:
// C#
using (Smtpclient = new Smtp())
{
client.Connect("smtp.example.org");
client.UseBestLogin("smtp", "password");
Console.WriteLine("Supported extensions:");
foreach (SmtpExtension extension in client.SupportedExtensions())
{
Console.WriteLine(extension.Name);
}
Console.WriteLine("Supports STARTTLS:");
bool supportsStartTLS = client.SupportedExtensions()
.Contains(SmtpExtension.StartTLS);
Console.WriteLine(supportsStartTLS);
client.Close();
}
' VB.NET
Using client As New Smtp()
client.Connect("smtp.example.org")
client.UseBestLogin("user", "password")
Console.WriteLine("Supported extensions:")
For Each extension As SmtpExtension In client.SupportedExtensions()
Console.WriteLine(extension.Name)
Next
Console.WriteLine("Supports STARTTLS:")
Dim supportsStartTLS As Boolean = client.SupportedExtensions() _
.Contains(SmtpExtension.StartTLS)
Console.WriteLine(supportsStartTLS)
client.Close()
End Using

