{"id":2000,"date":"2011-10-06T17:13:53","date_gmt":"2011-10-06T15:13:53","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2000"},"modified":"2014-06-04T09:17:34","modified_gmt":"2014-06-04T07:17:34","slug":"get-supported-authentication-methods-imap-pop3-smtp","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/get-supported-authentication-methods-imap-pop3-smtp","title":{"rendered":"Get supported authentication methods (IMAP, POP3, SMTP)"},"content":{"rendered":"<p>Not all servers support all authentication methods. It is sometimes good to know which methods are supported and which are not. This post explains how to get  supported authentication methods supported by the email server in .NET.<\/p>\n<div class=\"well\">\n<ul>\nYou can also read how to: <\/p>\n<li><a href=\"\/blog\/get-supported-server-extensions-imap-pop3-smtp\">Get supported server extensions (IMAP, POP3, SMTP)<\/a><\/li>\n<\/ul>\n<\/div>\n<p>It is very common for email servers to support different authentication methods for plain text connections and different methods for SSL (<em>ConnectSSL<\/em>) or TLS (<em>StartTLS<\/em>, <em>STLS<\/em>) secured sessions.<\/p>\n<p>Even though protocol commands and responses are different between server types (IMAP, POP3, and SMTP), API is very similar. We take great care to make it similar for all protocols (IMAP, POP3, SMTP). You can use <em>SupportedAuthenticationMethods<\/em> on <em>Imap<\/em>, <em>Pop3<\/em> or <em>Smtp<\/em> class to retrieve all authentication methods supported by the server.<\/p>\n<p>In return you&#8217;ll get a list of<\/p>\n<ul>\n<li><em>ImapAuthenticationMethod <\/em>objects in case of IMAP server<\/li>\n<li><em>Pop3AuthenticationMethod <\/em>objects in case of POP3 server<\/li>\n<li><em>SmtpAuthenticationMethod <\/em>objects in case of SMTP server<\/li>\n<\/ul>\n<p>Each class contains static properties that represent known authentication methods for example: <em>ImapAuthenticationMethod.CramMD5<\/em>, <em>ImapAuthenticationMethod.Login<\/em><\/p>\n<h2>IMAP<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing (Imap client = new Imap())\r\n{\r\n    client.Connect(&quot;imap.example.org&quot;);     \/\/ or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;);\r\n\r\n    foreach (var method in client.SupportedAuthenticationMethods())\r\n    {\r\n        Console.WriteLine(method.Name);\r\n    }\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;);\r\n\r\n    bool supportsCramMD5 = client.SupportedAuthenticationMethods()\r\n        .Contains(ImapAuthenticationMethod.CramMD5);\r\n\r\n    Console.WriteLine(supportsCramMD5);\r\n\r\n    client.Close();\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing client As New Imap()\r\n    client.Connect(&quot;imap.example.org&quot;)     ' or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;)\r\n\r\n    For Each method As ImapAuthenticationMethod In client.SupportedAuthenticationMethods()\r\n\t    Console.WriteLine(method.Name)\r\n    Next\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;)\r\n\r\n    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _\r\n        .Contains(ImapAuthenticationMethod.CramMD5)\r\n\r\n    Console.WriteLine(supportsCramMD5)\r\n\r\n    client.Close()\r\nEnd Using\r\n<\/pre>\n<p>For example Gmail produces following output:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSupported methods:\r\nXOAUTH\r\nXOAUTH2\r\n\r\nSupports CramMD5:\r\nFalse\r\n<\/pre>\n<p>As you can see this list is not entirely accurate as LOGIN command is supported by Google. <\/p>\n<p>The current IMAP protocol specification requires the implementation of the LOGIN command which uses clear-text passwords.<\/p>\n<p>Please also note that although LOGIN command send user and password in clear text, Gmail requires clients to use SSL (To connect you must use <em>ConnectSSL<\/em> method). This means that entire communication channel is secured using SSL (in the same way https is) and it is impossible to eavesdrop the password.<\/p>\n<h2>LOGINDISABLED<\/h2>\n<p>The current IMAP protocol specification requires the implementation of the LOGIN command which uses clear-text passwords.<\/p>\n<p>Many sites may choose to disable this command unless encryption is active (<em>ConnectSSL<\/em> or <em>StartTLS<\/em>) for security reasons.<\/p>\n<p>An IMAP server, especially the one that allows connecting without SSL, MAY advertise that the LOGIN command is disabled by including the LOGINDISABLED capability in the capability response. <\/p>\n<p>Here&#8217;s how to <a href=\"\/blog\/get-supported-server-extensions-imap-pop3-smtp\">check what extensions IMAP server supports<\/a>.<\/p>\n<p>The bottom line is that in most cases <em>UseBestLogin<\/em> method is going to chose appropriate authentication method for you and authenticate you.<\/p>\n<h2>POP3<\/h2>\n<p>Here&#8217;s how to <strong>get supported authentication methods for POP3<\/strong> protocol:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing (Pop3 client = new Pop3())\r\n{\r\n    client.Connect(&quot;pop3.example.org&quot;);     \/\/ or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;);\r\n\r\n    foreach (var method in client.SupportedAuthenticationMethods())\r\n    {\r\n        Console.WriteLine(method.Name);\r\n    }\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;);\r\n\r\n    bool supportsCramMD5 = client.SupportedAuthenticationMethods()\r\n        .Contains(Pop3AuthenticationMethod.CramMD5);\r\n\r\n    Console.WriteLine(supportsCramMD5);\r\n\r\n    client.Close();\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing client As New Pop3()\r\n    client.Connect(&quot;pop3.example.org&quot;)     ' or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;)\r\n\r\n    For Each method As Pop3AuthenticationMethod In client.SupportedAuthenticationMethods()\r\n\t    Console.WriteLine(method.Name)\r\n    Next\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;)\r\n\r\n    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _\r\n        .Contains(Pop3AuthenticationMethod.CramMD5)\r\n\r\n    Console.WriteLine(supportsCramMD5)\r\n\r\n    client.Close()\r\nEnd Using\r\n<\/pre>\n<p>In most cases <em>UseBestLogin<\/em> method is going to chose appropriate authentication method for you and authenticate you.<\/p>\n<h2>SMTP<\/h2>\n<p>Here&#8217;s how to <strong>get supported authentication methods for SMTP<\/strong> protocol:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing (Smtpclient = new Smtp())\r\n{\r\n    client.Connect(&quot;smtp.example.org&quot;);     \/\/ or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;smtp&quot;, &quot;password&quot;);\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;);\r\n\r\n    foreach (var method in client.SupportedAuthenticationMethods())\r\n    {\r\n        Console.WriteLine(method.Name);\r\n    }\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;);\r\n\r\n    bool supportsCramMD5 = client.SupportedAuthenticationMethods()\r\n        .Contains(SmtpAuthenticationMethod.CramMD5);\r\n\r\n    Console.WriteLine(supportsCramMD5);\r\n\r\n    client.Close();\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing client As New Smtp()\r\n    client.Connect(&quot;smtp.example.org&quot;)     ' or ConnectSSL for SSL\r\n    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    Console.WriteLine(&quot;Supported methods:&quot;)\r\n\r\n    For Each method As SmtpAuthenticationMethod In client.SupportedAuthenticationMethods()\r\n\t    Console.WriteLine(method.Name)\r\n    Next\r\n\r\n    Console.WriteLine(&quot;Supports CramMD5:&quot;)\r\n\r\n    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _\r\n        .Contains(SmtpAuthenticationMethod.CramMD5)\r\n\r\n    Console.WriteLine(supportsCramMD5)\r\n\r\n    client.Close()\r\nEnd Using\r\n<\/pre>\n<p>In most cases <em>UseBestLogin<\/em> method is going to chose appropriate authentication method for you and authenticate you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not all servers support all authentication methods. It is sometimes good to know which methods are supported and which are not. This post explains how to get supported authentication methods supported by the email server in .NET. You can also read how to: Get supported server extensions (IMAP, POP3, SMTP) It is very common for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,28,42,50,57],"class_list":["post-2000","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-pop3","tag-smtp","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2000"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=2000"}],"version-history":[{"count":9,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2000\/revisions"}],"predecessor-version":[{"id":4155,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2000\/revisions\/4155"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}