Using Email Templates Extensions

A special folder in the Templates folder, named Extensions contains extension scripts that provide new, custom template elements. These extensions may be called from within the inline scripts created in the other templates. The scripts are provided inside messages. The body of the messages is evaluated every time an unknown template element is encountered in a template. Within extensions, you can create new elements and new procedures.

Extensions do not function as templates by themselves, and the elements and procedures created in them must be activated by a template. With the following examples, a sample template is provided with each extension, so that you can see how each extension works.

Extension Examples

Calling template procedures

Custom elements that require script processing, are provided via Tcl procedures that start with etx_. The rest of the procedure name is the name of the new template element. The procedure will be called every time the element is encountered in a template, and the element name will be substituted with the value returned by the procedure. In general, if you find yourself creating the same scripts again and again within your templates, you may want to store that script as a procedure within the extensions folder.

For example, for a custom element named ¤t_time;, a procedure of the following form must be provided:

proc etx_current_time {args} {
return [clock format [clock seconds]]
}

This procedure introduces a new template element: ¤t_time; that provides the current time.

Rotating Text

This is a slightly more sophisticated example. It allows you to insert a random quote in the message created by the template. Here is the code:

# This extension provides "random" rotating text through a new
# template element named &rotating_text; Please look at the
# "Rotating text." template for a demonstration.
proc etx_rotating_text {args} {
set items {
{"I have never let my schooling interfere with my education." - Mark Twain}
{"Beware of the man of one book." - Thomas Aquinas}
{"Common sense is not so common." - Voltaire}
}
set count [llength $items]
set pseudo_random [expr [clock seconds] % $count]
return [lindex $items $pseudo_random]
}

The Tcl code at the end of the procedure selects one of the quotes randomly. With a little bit of Tcl code, you may modify this template to read the quotes from a file (or message) instead.

Download a lengthier version of this extension with more quotes!

Later, you can add this procedure to a template to do an automatic call to the procedure. Somewhere within your template, you might have something that looks like this:

Here is another "random" quote:
"&rotating_text;"

Download the Rotating Text template to see how it works!

Working with external applications

Tcl cooperates with local files and applications just as easily in extensions as with inline scripts.

This extension demonstrates how to invoke an external application from a template. Let's assume you have an application called salesapp.exe that provides the current sales performance data when invoked. To insert these data directly into a message, you could write an extension as follows:

proc etx_sales_data {args} {
return [exec salesapp.exe]
}

That's it! (You might have to include extra arguments to your salesapp.exe, but that's beyond the scope of this simple example).

Processing an Order

This example demonstrates how you may access the different data fields specified in an email. A sample file is provided below to illustrate this. The extension will parse the email and add new template elements for each data field.

Note: This extension requires that you know about the specified format of the data in the email. In other words, it can be modified to work for most situations, but was written based on a message of the following format:

Item : Product
Quantity : 1
Shipment : Desired Shipment Method
Name : Customer Name
Email : customer@email.address
Phone : 888-8888
Fax :
Company : Customer's Company
Address : Customer's Address
City : City
State : State
Zip : 12345
Country : Country
Payment : Payment Method
NameOnCard : Name on the card
CardNo : xxxxxxxxxxxxxxxxxxxx
Exp : 01/00

The extension gives you the ability to read through and access data from an email. This example proves extremely useful when dealing with email from orders placed via web pages.

Download this extension!

The example message template sends a "confirmation of order" email to the customer with whatever data you would like to include from the order email.

Download this template!

Bulk Email

This example demonstrates how to send an email to all the subscribers on your company mailing list. Email Templates™; will personalize each email for your subscribers so that it does not appear that they are receiving a bulk email. You supply Email Templates™ with the location of your subscribers list, create the message to be sent, and select the Bulk Email Template.

This extension example demonstrates how Email Templates™ can handle the repetitive task of sending email to a company's subscriber list. This extension can prove extremely useful when you need to send out that monthly electronic news letter or new product announcement to your subscribers. You provide the body of the message and the location of the subscribers file, and the extension will take care of the rest.

This example demonstrates how to access each column of data from a tab separated file. (i.e. Microsoft Excel) And, if you decide to add some new information to your file, the code will take care of the change itself and give you access to the new data. There is no need to make any changes to the code, simply modify your data by adding another tab separated column.

Download the Bulk Email extension!

Download the Bulk Email template!

Using VBScript within extensions

You can also include VBScript within extensions. To add VBScript code to your extensions, you will need to include them in your Tcl script as follows:

proc etx_my_procedure {args} {
return [et vbscript {
<Your VBScript>
<goes in here>
}]
}