Using a text file as an email HTML template

Here is a simple way to use a text file as a template for an HTML email.

Assuming a queue item with Customer ID, Customer Name, Balance, and Due Date, create a template file. For each field you want replaced with an actual value, put it inside { and }:

Billing information for customer {Customer Name}:<BR>
<TABLE>
	<TR>
		<TD>Customer ID</td><TD>{Customer ID}</td>
	</tr>
	<TR>
		<TD>Balance</td><TD>{Balance}</td>
	</tr>
	<TR>
		<TD>Due Date</td><TD>{Due Date}</td>
	</tr>
</table>

Read this file into a string variable:

image

Loop through the keys in SpecificContent and perform a replace on the string variable:

image
templateText.Replace("{" + currentItem + "}",transactionItem.SpecificContent(currentItem).ToString)

Use the variable in the Body of your email activity, making sure to check the “Is Body HTML” property:

image

Resulting email:

2 Likes

@postwick

Thank you for sharing this with us