This topic is locked

Sending templated email messages

5/4/2012 3:17:53 PM
ASPRunnerPro Tips and tricks
admin

Composing good looking HTML emails in your code is a tedious task. Luckily there is a better way to design your emails. Fire up your favorite HTML or text editor and compose your email there. Fill it with template variables like ##User_name##. Here is the sample "thank you for your order" email template.

<P><STRONG>Thanks for your order, ##User_name##!</STRONG> </P>

<P>If you need to check the status of your order or make changes, please visit our home page at ##Website_URL##, login and edit your orders. </P>

<P><STRONG>Personal info</STRONG> </P>

<P><STRONG>Email Address:</STRONG> ##User_email## </P>

<P><STRONG>Billing Address:</STRONG> ##Billing_address## <STRONG>Shipping Address:</STRONG> ##Shipping Address## </P>

<P><STRONG>Order Total:</STRONG> ##total## </P>

<P>Thanks again for shopping with us!</P>


We are going to save this template to order.txt file. Here is the code that loads template, replaces variables and sends the email:



' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("order.txt"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing
' replace variables '

email_message = Replace(email_message,"##User_name##","Next USA president")

email_message = Replace(email_message,"##User_email##","president@whitehouse.gov")

email_message = Replace(email_message,"##Billing_address##","1600 Pennsylvania Avenue")

email_message = Replace(email_message,"##Shipping Address##","1600 Pennsylvania Avenue")

email_message = Replace(email_message,"##Total##","123.56")

email_message = Replace(email_message,"##Website_URL##","http://mycoolwebsite.com";)
' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")="president@whitehouse.gov"

params("subject")="Thank you for your order"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)