Email template extensions are used to extend the functionality of email templates. These extensions are referred to in the email templates using the <extensionName> syntax. For example, the EmailUtilityExtension is referenced in email templates using $email_utility. Additional extensions can be created to further extend the email template functionality.
Below is a code sample of an email extension.
using Telligent.Evolution.Extensibility.Email.Version1;
namespace Examples.EmailExtensions
{
public class HelloWorldExtension : IEmailTemplateExtension
{
private HelloWorld hello;
public string ExtensionName
{
get { return "hello_world"; }
}
public object Extension
{
get { return hello; }
}
public string Name
{
get { return string.Format("Hello World Extension for Email Templates ({0})", ExtensionName); }
}
public string Description
{
get { return "Enables email templates to access HelloWorld."; }
}
public void Initialize()
{
hello = new HelloWorld();
}
}
public class HelloWorld
{
public string SayHello()
{
return "Hello email!";
}
}
}
This extension is referenced in an email template using $hello_world (taken from the ExtensionName property). The SayHello method is referenced using $hello_world.SayHello(). Calling this in an email template will return the "Hello email!" string to the email template.
Once an email extension is created, it needs to be enabled on the site. Dropping the .dll archive into the Web/bin folder will cause the site to pick up the new extension, but it won't enable it right away. Navigating to /controlpanel/Settings/ManagePlugins.aspx will show a list of all plugins (including email template extensions) found. Enable the newly created extension and save the page. Email templates may now use the extension! Be sure to also copy the archive into the Job Scheduler folder as well to ensure the extension is available to all email templates.
An IEmailTemplateExtension can be as complex or as simple as it needs to be. IEmailTemplateExtension extends the IPlugin interface, making it easy to port a plugin created for widgets to be used in email, also.