{"id":1270,"date":"2010-10-25T15:33:55","date_gmt":"2010-10-25T13:33:55","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1270"},"modified":"2014-04-15T17:34:11","modified_gmt":"2014-04-15T15:34:11","slug":"access-custom-email-header-using-pop3","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/access-custom-email-header-using-pop3","title":{"rendered":"Access custom email header using POP3"},"content":{"rendered":"<p>Most common email headers like <a href=\"\/blog\/get-common-email-fields-subject-text-with-pop3\">From, Subject, Date<\/a>, <a href=\"\/blog\/how-to-access-to-cc-bcc-fields\">To, Cc<\/a> etc. are exposed by <em>IMail <\/em>interface as properties. Those properties contain parsed information and return <strong>strong typed objects<\/strong> like <em>DateTime<\/em>&#8216;s, string collections, <em>MailAddress <\/em>collections.<\/p>\n<p>There are times however that you need to access non-standard email header. Good example is a need to get a spam value that your POP3 server assigns to every email by inserting additional &#8216;x-spam&#8217; header.<\/p>\n<p>For this purpose you can always use <em>IMail.Document.Root.Headers<\/em> collection to <strong>access any non-standard and standard header<\/strong>.<\/p>\n<p>If you only need to access email headers consider using <em>GetHeadersByUID<\/em> method which doesn&#8217;t download entire message, but only headers. It uses POP3 TOP command. The sample below downloads entire message.<\/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;pop3.example.com&quot;);    \/\/ or ConnectSSL for SSL\r\n            pop3.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n            MailBuilder builder = new MailBuilder();\r\n            foreach (string uid in pop3.GetAll())\r\n            {\r\n                var eml = pop3.GetMessageByUID(uid);\r\n                IMail email = builder.CreateFromEml(eml);\r\n                Console.WriteLine(&quot;subject: {0}&quot;, email.Subject);\r\n\r\n                \/\/ Get custom header:\r\n                string header = email.Document.Root.Headers&#x5B;&quot;x-spam&quot;];\r\n                Console.WriteLine(&quot;x-spam: {0}&quot;, header);\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.Mail\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;pop3.example.com&quot;)    ' or ConnectSSL for SSL\r\n            pop3.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n            Dim builder As New MailBuilder()\r\n            For Each uid As String In pop3.GetAll()\r\n                Dim eml = pop3.GetMessageByUID(uid)\r\n                Dim email As IMail = builder.CreateFromEml(eml)\r\n                Console.WriteLine(&quot;subject: {0}&quot;, email.Subject)\r\n\r\n                ' Get custom header:\r\n                Dim header As String = email.Document.Root.Headers(&quot;x-spam&quot;)\r\n                Console.WriteLine(&quot;x-spam: {0}&quot;, header)\r\n            Next\r\n            pop3.Close()\r\n        End Using\r\n\r\n    End Sub\r\nEnd Module\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Most common email headers like From, Subject, Date, To, Cc etc. are exposed by IMail interface as properties. Those properties contain parsed information and return strong typed objects like DateTime&#8216;s, string collections, MailAddress collections. There are times however that you need to access non-standard email header. Good example is a need to get a spam [&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,57],"class_list":["post-1270","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-email-component","tag-pop3","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1270"}],"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=1270"}],"version-history":[{"count":4,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":4576,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1270\/revisions\/4576"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}