|  | 
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
| (Classic ASP) Create HTML Email ReplyThe goal of this example is to create a new HTML body where the new reply HTML is at the top, and the original HTML body is below. The .eml files for this example are available at HTML Reply Email Samples (.eml) Note: This is only one of a million ways to do it.. 
 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Email") set email = Server.CreateObject("Chilkat.Email") ' To create this example, I used Mozilla Thunderbird (with a GMail accont) ' to first send a simple HTML email to my chilkatsoft.com email address. I then ' used Thunderbird to reply with more HTML. ' I then saved both emails as .eml files. These are available at ' http://chilkatdownload.com/example_data/htmlreplyemail.zip ' Load the .eml for the 1st email that was received. This is the original ' HTML email before the reply HTML is added. success = email.LoadEml("qa_data/eml/receivedHtmlEmail.eml") If (success <> 1) Then Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>" Response.End End If ' If this email doesn't have an HTML body, then do something else... ' (that's for another example maybe?) If (email.HasHtmlBody() = 0) Then Response.Write "<pre>" & Server.HTMLEncode( "Email does not have an HTML body..") & "</pre>" Response.End End If ' Get the HTML body in a StringBuilder.. ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbHtml = Server.CreateObject("Chilkat.StringBuilder") success = sbHtml.Append(email.GetHtmlBody()) ' The HTML body contains this: ' <html><head> ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> ' </head> ' <body bgcolor="#FFFFFF" text="#000000"> ' <font face="Calibri"><br> ' This is a test <font color="#3366ff"><i>HTML email</i></font>...<br> ' <br> ' <br> ' </font> ' </body> ' </html> ' Make sure the BODY tags are lowercase. numReplaced = sbHtml.Replace("<BODY","<body") numReplaced = sbHtml.Replace("</BODY","</body") ' Get the HTML within the "body" open/close tags ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbBodyContent = Server.CreateObject("Chilkat.StringBuilder") success = sbBodyContent.Append(sbHtml.GetAfterBetween("<body",">","</body>")) ' Replace what we just extracted with a marker.. numReplaced = sbHtml.Replace(sbBodyContent.GetAsString(),"TO_BE_UPDATED") ' Create a template for the new body: ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder") set sbTemplate = Server.CreateObject("Chilkat.StringBuilder") bCrlf = 1 success = sbTemplate.AppendLine("REPLY_HTML_CONTENT",bCrlf) success = sbTemplate.AppendLine("<br>",bCrlf) success = sbTemplate.AppendLine("<div class=""moz-signature"">Best Regards,<br>",bCrlf) success = sbTemplate.AppendLine(" John Smith<br>",bCrlf) success = sbTemplate.AppendLine(" Chilkat Software, Inc.<br>",bCrlf) success = sbTemplate.AppendLine(" <p>",bCrlf) success = sbTemplate.AppendLine(" <a href=""https://twitter.com/chilkatsoft"">Follow Chilkat on",bCrlf) success = sbTemplate.AppendLine(" Twitter</a>",bCrlf) success = sbTemplate.AppendLine(" </p>",bCrlf) success = sbTemplate.AppendLine("</div>",bCrlf) success = sbTemplate.AppendLine("<div class=""moz-cite-prefix"">On 2/8/2017 4:25 PM, Chilkat Support",bCrlf) success = sbTemplate.AppendLine(" wrote:<br>",bCrlf) success = sbTemplate.AppendLine("</div>",bCrlf) success = sbTemplate.AppendLine("<blockquote>",bCrlf) success = sbTemplate.AppendLine("ORIGINAL_BODY_CONTENT",bCrlf) success = sbTemplate.AppendLine("</blockquote>",bCrlf) success = sbTemplate.AppendLine("<br>",bCrlf) ' Replace the markers in the template with actual HTML. ' First our reply HTML: myHtmlReplyBody = "This is my <font color=""#6600cc""><b>reply HTML</b></font><br>" numReplaced = sbTemplate.Replace("REPLY_HTML_CONTENT",myHtmlReplyBody) ' Now for the original HTML body content: numReplaced = sbTemplate.Replace("ORIGINAL_BODY_CONTENT",sbBodyContent.GetAsString()) ' Insert into sbHtml: numReplaced = sbHtml.Replace("TO_BE_UPDATED",sbTemplate.GetAsString()) ' Use sbHtml as the new HTML body.. email.SetHtmlBody sbHtml.GetAsString() ' Examine the result HTML. Response.Write "<pre>" & Server.HTMLEncode( sbHtml.GetAsString()) & "</pre>" ' Save the email. success = email.SaveEml("qa_output/emailWithUpdatedHtmlBody.eml") ' Note: To finish creating the reply email, modify the To/From/CC headers, ' the subject, etc. You may also with to iterate over the headers (from 1 to NumHeaderFields) ' and selectively remove all except the particular headers you wish to keep. ' You should keep: MIME-Version, Content-Type, Message-ID. Chilkat will automaticaly ' generate and replace the Message-ID at the time of sending. You'll want to replace ' the Date header with the current date/time. ' %> </body> </html> | ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.