{"id":1272,"date":"2010-10-25T15:34:38","date_gmt":"2010-10-25T13:34:38","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1272"},"modified":"2013-06-25T16:07:39","modified_gmt":"2013-06-25T14:07:39","slug":"issue-a-custom-command-to-pop3-server","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/issue-a-custom-command-to-pop3-server","title":{"rendered":"Issue a custom command to POP3 server"},"content":{"rendered":"<p>You can send any command to POP3 server using Mail.dll and receive servers&#8217;s response easy.<\/p>\n<p>In this example we will issue LIST command. LIST command is used to check the email size without downloading it from the POP3 server.<\/p>\n<p>There are 2 versions of the LIST command. First takes message number parameter:<\/p>\n<p><code>LIST messageNumber<\/code><\/p>\n<p>We are asking for specific message here, which means that we expect to receive single line response.<\/p>\n<p>Remember that message numbers on POP3 servers start from 1.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing System;\r\nusing Limilabs.Client.POP3;\r\n\r\nclass Program\r\n{\r\n    static void Main(string&#x5B;] args)\r\n    {\r\n        using (Pop3 pop3 = new Pop3())\r\n        {\r\n            pop3.Connect(&quot;server.example.com&quot;);\r\n            pop3.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n            Pop3Response response = pop3.SendCommand(&quot;LIST &quot; + 1);\r\n\r\n            \/\/ We expect string in following format: &quot;0 32768&quot;\r\n            string sizeInBytes = response.Message.Split(' ')&#x5B;1];\r\n\r\n            Console.WriteLine(sizeInBytes);\r\n            pop3.Close();\r\n        }\r\n    }\r\n};\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nImports System\r\nImports Limilabs.Client.POP3\r\n\r\nPublic Module Module1\r\n    Public Sub Main(ByVal args As String())\r\n\r\n        Using pop3 As New Pop3()\r\n            pop3.Connect(&quot;server.example.com&quot;)\r\n            pop3.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n            Dim response As Pop3Response = pop3.SendCommand(&quot;LIST &quot; + 1)\r\n\r\n            ' We expect string in following format: &quot;0 32768&quot;\r\n            Dim sizeInBytes As String = response.Message.Split(&quot; &quot;c)(1)\r\n\r\n            Console.WriteLine(sizeInBytes)\r\n            pop3.Close()\r\n        End Using\r\n\r\n    End Sub\r\nEnd Module\r\n<\/pre>\n<p>Second version is LIST command without any arguments:<\/p>\n<p><code>LIST<\/code><\/p>\n<p>It gets the size of every message that is currently stored on the POP3 server &#8211; server replies with multi-line response:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing System;\r\nusing Limilabs.Mail;\r\nusing Limilabs.Client.POP3;\r\n\r\nclass Program\r\n{\r\n    static void Main(string&#x5B;] args)\r\n    {\r\n        using (Pop3 pop3 = new Pop3())\r\n        {\r\n            pop3.Connect(&quot;server.company.com&quot;);\r\n            pop3.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n            Pop3Response response = pop3.SendMultiLineCommand(&quot;LIST&quot;);\r\n\r\n            foreach(string line in response.GetLines())\r\n            {\r\n                \/\/ We expect following format: &quot;0 32768&quot;\r\n                string&#x5B;] tmp = line.Split(' ');\r\n                Console.WriteLine(&quot;Message number {0} is {1} bytes long.&quot;,\r\n                                  tmp&#x5B;0],\r\n                                  tmp&#x5B;1]);\r\n            }\r\n            pop3.Close();\r\n        }\r\n    }\r\n};\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nImports System\r\nImports Limilabs.Client.POP3\r\n\r\nPublic Module Module1\r\n    Public Sub Main(ByVal args As String())\r\n\r\n        Using pop3 As New Pop3()\r\n            pop3.Connect(&quot;server.company.com&quot;)\r\n            pop3.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n            Dim response As Pop3Response = pop3.SendMultiLineCommand(&quot;LIST&quot;)\r\n\r\n            For Each line As String In response.GetLines()\r\n                ' We expect following format: &quot;0 32768&quot;\r\n                Dim tmp As String() = line.Split(&quot; &quot;c)\r\n                Console.WriteLine(&quot;Message number {0} is {1} bytes long.&quot;, tmp(0), tmp(1))\r\n            Next\r\n            pop3.Close()\r\n        End Using\r\n\r\n    End Sub\r\nEnd Module\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can send any command to POP3 server using Mail.dll and receive servers&#8217;s response easy. In this example we will issue LIST command. LIST command is used to check the email size without downloading it from the POP3 server. There are 2 versions of the LIST command. First takes message number parameter: LIST messageNumber We [&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,33,42,79,57],"class_list":["post-1272","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-email-component","tag-pop3","tag-pop3-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1272"}],"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=1272"}],"version-history":[{"count":5,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1272\/revisions"}],"predecessor-version":[{"id":4031,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1272\/revisions\/4031"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}