{"id":2188,"date":"2011-12-28T11:53:34","date_gmt":"2011-12-28T09:53:34","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2188"},"modified":"2016-09-09T10:58:09","modified_gmt":"2016-09-09T08:58:09","slug":"reply-to-email","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/reply-to-email","title":{"rendered":"Reply to an email"},"content":{"rendered":"<p>You can use Mail.dll to easy reply to an HTML and plain-text emails.<\/p>\n<p><em>ReplyBuilder <\/em>class allows you to specify <strong>custom HTML and plain-text reply templates<\/strong>. Mail.dll will parse HTML, extract body part, and build-in template engine will do the rest to create nicely formatted reply with all attachments, To and Cc fields set.<\/p>\n<p>The next great thing is that plain-text version of the email is generated automatically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2011\/12\/reply.png\" alt=\"\" title=\"reply\" width=\"429\" height=\"388\" class=\"aligncenter size-full\" \/><\/p>\n<p>You can also take advantage of <em>ReplyAll <\/em>method that makes it easy to reply to all: senders of the message and all To and Cc recipients<\/p>\n<p>In our example we\u2019ll use Mail.dll <a href=\"\/mail\">.NET IMAP component<\/a> to download first message from an IMAP server. Then we\u2019ll use <em>ReplyBuilder  <\/em> to create a reply email message. Finally we\u2019ll use Mail.dll SMTP client to send this message.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nIMail original = GetFirstMessage();\r\n\r\nReplyBuilder replyBuilder = original.Reply();\r\n\r\n\/\/ You can specify your own, custom, body and subject templates:\r\nreplyBuilder.HtmlReplyTemplate = @&quot;&lt;!DOCTYPE html PUBLIC &quot;&quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot;&quot; &quot;&quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&quot;&gt;\r\n    &lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;meta http-equiv=&quot;&quot;Content-Type&quot;&quot; content=&quot;&quot;text\/html; charset=UTF-8&quot;&quot; \/&gt;\r\n        &lt;title&gt;&#x5B;Subject]&lt;\/title&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n    &#x5B;Html]\r\n    &lt;br \/&gt;&lt;br \/&gt;\r\n    On &#x5B;Original.Date] &#x5B;Original.Sender.Name] wrote:\r\n    &lt;blockquote style=&quot;&quot;margin-left: 1em; padding-left: 1em; border-left: 1px #ccc solid;&quot;&quot;&gt;\r\n        &#x5B;QuoteHtml]\r\n    &lt;\/blockquote&gt;\r\n    &lt;\/body&gt;\r\n    &lt;\/html&gt;&quot;;\r\nreplyBuilder.SubjectReplyTemplate = &quot;Re: &#x5B;Original.Subject]&quot;;\r\n\r\nreplyBuilder.Html = &quot;Alice, &lt;br\/&gt;&lt;br\/&gt;thanks for your email.&quot;;\r\n\r\nMailBuilder builder = replyBuilder.ReplyToAll(\r\n    new MailBox(&quot;bob@example.org&quot;, &quot;Bob&quot;));\r\n\r\n\/\/ You can add attachments to your reply\r\n\/\/builder.AddAttachment(&quot;report.csv&quot;);\r\n\r\nIMail reply = builder.Create();\r\n\r\nusing (Smtp smtp = new Smtp())\r\n{\r\n    smtp.Connect(&quot;smtp.example.com&quot;); \/\/ or ConnectSSL\r\n    smtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n    smtp.SendMessage(reply);\r\n    smtp.Close();\r\n}\r\n\r\nstatic IMail GetFirstMessage()\r\n{\r\n    IMail email;\r\n    using (Imap imap = new Imap())\r\n    {\r\n        imap.Connect(&quot;imap.example.com&quot;); \/\/ or ConnectSSL if you want to use SSL\r\n        imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n        List&lt;long&gt; uids = imap.GetAll();\r\n        if (uids.Count == 0)\r\n            throw new Exception(&quot;There are no messages&quot;);\r\n        var eml = imap.GetMessageByUID(uids&#x5B;0]); \r\n        email = new MailBuilder().CreateFromEml(eml);                \r\n        imap.Close();\r\n    }\r\n    return email;\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim original As IMail = GetFirstMessage()\r\n\r\nDim replyBuilder As ReplyBuilder = original.Reply()\r\n\r\n' You can specify your own, custom, body and subject templates:\r\nreplyBuilder.HtmlReplyTemplate = _\r\n&quot;&lt;!DOCTYPE html PUBLIC &quot;&quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot;&quot; &quot;&quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&quot;&gt;&quot; + _\r\n&quot; &lt;html&gt;&quot; +  _\r\n&quot; &lt;head&gt;&quot; +  _\r\n&quot;    &lt;meta http-equiv=&quot;&quot;Content-Type&quot;&quot; content=&quot;&quot;text\/html; charset=UTF-8&quot;&quot; \/&gt;&quot; +  _\r\n&quot;    &lt;title&gt;&#x5B;Subject]&lt;\/title&gt;&quot; +  _\r\n&quot; &lt;\/head&gt;&quot; +  _\r\n&quot; &lt;body&gt;&quot; +  _\r\n&quot;  &#x5B;Html]&quot; +  _\r\n&quot;  &lt;br \/&gt;&lt;br \/&gt;&quot; +  _\r\n&quot;  On &#x5B;Original.Date] &#x5B;Original.Sender.Name] wrote:&quot; +  _\r\n&quot;  &lt;blockquote style=&quot;&quot;margin-left: 1em; padding-left: 1em; border-left: 1px #ccc solid;&quot;&quot;&gt;&quot; +  _\r\n&quot;    &#x5B;QuoteHtml]&quot; +  _\r\n&quot;  &lt;\/blockquote&gt;&quot; +  _\r\n&quot; &lt;\/body&gt;&quot; +  _\r\n&quot; &lt;\/html&gt;&quot;\r\nreplyBuilder.SubjectReplyTemplate = &quot;Re: &#x5B;Original.Subject]&quot;\r\n\r\nDim builder As MailBuilder = replyBuilder.ReplyToAll( _\r\n    New MailBox(&quot;bob@example.org&quot;, &quot;Bob&quot;))\r\n\r\n' You can add attachments to your reply\r\n'builder.AddAttachment(&quot;report.csv&quot;)\r\n\r\nDim reply As IMail = builder.Create()\r\n\r\nUsing smtp As New Smtp()\r\n\tsmtp.Connect(&quot;smtp.example.com&quot;) ' or ConnectSSL\r\n\tsmtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\tsmtp.SendMessage(reply)\r\n\tsmtp.Close()\r\nEnd Using\r\n\r\nPrivate Shared Function GetFirstMessage() As IMail\r\n\tDim email As IMail\r\n\tUsing imap As New Imap()\r\n\t\timap.Connect(&quot;imap.example.com&quot;)\r\n\t\t' or ConnectSSL if you want to use SSL\r\n\t\timap.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\t\tDim uids As List(Of Long) = imap.GetAll()\r\n\t\tIf uids.Count = 0 Then\r\n\t\t\tThrow New Exception(&quot;There are no messages&quot;)\r\n\t\tEnd If\r\n\t\tDim eml = imap.GetMessageByUID(uids(0))\r\n\t\temail = New MailBuilder().CreateFromEml(eml)\r\n\t\timap.Close()\r\n\tEnd Using\r\n\tReturn email\r\nEnd Function\r\n<\/pre>\n<p>In the reply templates (<em>HtmlReplyTemplate<\/em>, <em>TextReplyTemplate<\/em>, <em>SubjectReplyTemplate<\/em>) you have access to following fields:<\/p>\n<ul>\n<li><em>string Subject<\/em> &#8211; subject of the reply (e.g. [Subject])<\/li>\n<li><em>string Text<\/em> &#8211; plain text of the reply (e.g. [Test])<\/li>\n<li><em>string Html<\/em> &#8211; html of the reply (e.g. [Html])<\/li>\n<li><em>string QuoteText<\/em> &#8211; original text quoted using &#8216;>&#8217; chars (e.g. [QuoteText])<\/li>\n<li><em>string QuoteHtml<\/em> &#8211; body contents of original html or original text converted to html (e.g. [QuoteHtml])<\/li>\n<li><em>IMail Original<\/em> &#8211; original email you are relying to and all its properties (e.g. [Original.Subject], [Original.Sender.Address])<\/li>\n<\/ul>\n<p>Please note that you can <a href=\"\/blog\/email-template-engine\">use any template and data to generate actual reply email<\/a> (<em>ReplyBuilder.Html<\/em> and <em>ReplyBuilder.Text<\/em>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use Mail.dll to easy reply to an HTML and plain-text emails. ReplyBuilder class allows you to specify custom HTML and plain-text reply templates. Mail.dll will parse HTML, extract body part, and build-in template engine will do the rest to create nicely formatted reply with all attachments, To and Cc fields set. The next [&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":[33,50],"class_list":["post-2188","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-email-component","tag-smtp"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2188"}],"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=2188"}],"version-history":[{"count":11,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2188\/revisions"}],"predecessor-version":[{"id":5084,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2188\/revisions\/5084"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}