{"id":2827,"date":"2012-05-15T15:17:09","date_gmt":"2012-05-15T13:17:09","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2827"},"modified":"2014-11-20T21:14:32","modified_gmt":"2014-11-20T19:14:32","slug":"folder-access-with-imap","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/folder-access-with-imap","title":{"rendered":"Folder access with IMAP"},"content":{"rendered":"<p>This article describes how to access different folder then inbox using Mail.dll <a href=\"\/mail\">IMAP library<\/a>.<\/p>\n<p>In most cases the first thing you need from an IMAP server is to access INBOX folder. Mail.dll has a special method for that, as this is the only folder that must exist on every IMAP server. It&#8217;s <em>Imap.SelectInbox<\/em>.<\/p>\n<p>Most servers, of course, allow IMAP client to access other folders as well. You can <a href=\"\/blog\/list-all-folders-using-imap\">list all IMAP folders<\/a> using <em>Imap.GetFolders<\/em> method.<\/p>\n<p>If you want to <strong>access different IMAP folder<\/strong> than Inbox, you need to use overloaded <em>Imap.Select <\/em>method which takes string parameter (folder name) or <em>FolderInfo <\/em> parameter (returned from a call to <em>Imap.GetFolders<\/em> method).<\/p>\n<p>After that you can use <em>GetAll<\/em>, <em>Search<\/em> and <em>GetMessageByUID<\/em> methods to search and download email messages.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing (Imap imap = new Imap())\r\n{\r\n    imap.Connect(&quot;imap.example.com&quot;);    \/\/ or ConnectSSL for SSL\r\n    imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    imap.Select(&quot;Sent items&quot;);\r\n\r\n    List&lt;long&gt; uids = imap.GetAll();\r\n\r\n    foreach (long uid in uids)\r\n    {\r\n        IMail email = new MailBuilder()\r\n            .CreateFromEml(imap.GetMessageByUID(uid));\r\n        string subject = email.Subject;\r\n    }\r\n    imap.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing imap As New Imap()\r\n\timap.Connect(&quot;imap.example.com&quot;)\t' or ConnectSSL for SSL\r\n\timap.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n\timap.&#x5B;Select](&quot;Sent items&quot;)\r\n\r\n\r\n\tDim uids As List(Of Long) = imap.GetAll()\r\n\r\n\tFor Each uid As Long In uids\r\n\t\tDim email As IMail = New MailBuilder().CreateFromEml(imap.GetMessageByUID(uid))\r\n\t\tDim subject As String = email.Subject\r\n\tNext\r\n\timap.Close()\r\nEnd Using\r\n<\/pre>\n<p>There is<strong> no established standard on naming common IMAP folders<\/strong> like &#8216;Sent mail&#8217;, &#8216;Spam&#8217; etc. However some servers support XLIST command (Gmail) or SpecialUse extension that allow to <a href=\"\/blog\/common-imap-folders\">identify common folders on this particular IMAP server<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to access different folder then inbox using Mail.dll IMAP library. In most cases the first thing you need from an IMAP server is to access INBOX folder. Mail.dll has a special method for that, as this is the only folder that must exist on every IMAP server. It&#8217;s Imap.SelectInbox. Most servers, [&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,77,57],"class_list":["post-2827","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-imap-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2827"}],"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=2827"}],"version-history":[{"count":19,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2827\/revisions"}],"predecessor-version":[{"id":4855,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2827\/revisions\/4855"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}