{"id":1287,"date":"2010-10-25T15:39:42","date_gmt":"2010-10-25T13:39:42","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1287"},"modified":"2014-08-16T12:07:46","modified_gmt":"2014-08-16T10:07:46","slug":"send-raw-data-eml-file","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/send-raw-data-eml-file","title":{"rendered":"Send raw data (*.eml file)"},"content":{"rendered":"<p>This post describes how to <strong>send raw eml email data<\/strong> as email message using SMTP server.<\/p>\n<div class=\"well\">\nIn most cases you don&#8217;t need to send raw eml data.<br \/>\nTake a look at those topics, they may be better describing your needs:<\/p>\n<ul>\n<li><a href=\"\/blog\/send-email\">Send email<\/a><\/li>\n<li><a href=\"\/blog\/send-html-email\">Send HTML email<\/a><\/li>\n<li><a href=\"\/blog\/send-email-with-attachment\">Send email with attachment<\/a><\/li>\n<\/ul>\n<\/div>\n<p>*.eml extension is a standard extension used for storing email files. Eml file contains raw data received from POP3 or IMAP server. You can use <em>GetMessageByUID<\/em> on <em>Pop3 <\/em>or <em>Imap <\/em>class to obtain it. It can be also created using <em>IMail.Render<\/em> method:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nMailBuilder builder = new MailBuilder();\r\nbuilder.Subject = &quot;Test&quot;;\r\nbuilder.Text = &quot;This is plain text message.&quot;;\r\nbuilder.From.Add(new MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;));\r\nbuilder.To.Add(new MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;));\r\nIMail email = builder.Create();\r\nbyte&#x5B;] eml = email.Render();\r\n<\/pre>\n<p>Eml file includes all attachments, visual elements, email body in text, HTML (if defined) formats and email headers (such as: from, to, subject, date and so on).<\/p>\n<p>When sending email message using SMTP protocol you must fill three <em>SmtpMail<\/em> class properties:<\/p>\n<ul>\n<li>From &#8211; FROM command dialogue<\/li>\n<li>To &#8211; RCPT TO command in SMTP dialogue<\/li>\n<li>RawEmlData &#8211; DATA command in SMTP dialogue<\/li>\n<\/ul>\n<p>As you can see both &#8216;from address&#8217; and &#8216;recipient&#8217; are duplicated &#8211; they also appear in eml data as email From and To headers. <em>SmtpMail<\/em> has helper methods, such as <em>CreateFromEmlFile <\/em>or <em>CreateFromEml<\/em> that parse eml data and fill all properties required for SMTP communication. <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing Limilabs.Client.SMTP;\r\n\r\nclass Program\r\n{\r\n    static void Main(string&#x5B;] args)\r\n    {\r\n        using (Smtp smtp = new Smtp())\r\n        {\r\n            smtp.Connect(&quot;server.company.com&quot;);\r\n            smtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n            SmtpMail smtpMail = SmtpMail.CreateFromEmlFile(@&quot;c:\\email.eml&quot;);\r\n\r\n            smtp.SendMessage(smtpMail);\r\n            smtp.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 Limilabs.Client.SMTP\r\n\r\nPublic Module Module1\r\n    Public Sub Main(ByVal args As String())\r\n        Using smtp As New Smtp()\r\n            smtp.Connect(&quot;server.company.com&quot;)\r\n            smtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n            Dim smtpMail As SmtpMail = smtpMail.CreateFromEmlFile(&quot;c:\\email.eml&quot;)\r\n\r\n            smtp.SendMessage(SmtpMail)\r\n            smtp.Close()\r\n        End Using\r\n    End Sub\r\nEnd Module\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This post describes how to send raw eml email data as email message using SMTP server. In most cases you don&#8217;t need to send raw eml data. Take a look at those topics, they may be better describing your needs: Send email Send HTML email Send email with attachment *.eml extension is a standard extension [&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,20,50,57],"class_list":["post-1287","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-eml","tag-smtp","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1287"}],"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=1287"}],"version-history":[{"count":7,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1287\/revisions"}],"predecessor-version":[{"id":4769,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1287\/revisions\/4769"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}