WebHare 4.16 adds PrepareMailWitty as a replacement for the MakeEmailComposer API. We may deprecate the old API in the far future. New projects should always use the new API .

Simple usage:

  OBJECT outmail := PrepareMailWitty(Resolve("mytemplate.witty"));
  outmail->mergerecord := [ firstname := "Lisa" ];

with the following Wittytemplate:

    <title>My subject</title>
    <div id="test">Hi [firstname]</div>


PrepareMailWitty can wrap the email in a template by specifying a witty resource as the 'mailtemplate' option. A mailtemplate looks like this:

    <div>Standard header</div>
    <slot name="mailbody"></slot>
    <div>Standard footer</div>

The slot[name=mailbody] element is replaced with the original email. Stylesheets, mailsubjects and wh-mailcomposer- metatags are also merged into the original email.

Tollium preview 

Once you've switched to using PrepareMailWitty it's easy to add a debug/test option in your Tollium applications. Although this is not required it will be useful when building and testing mail templates. 

To ensure your preview and live versions don't diverge too much, you should wrap your PrepareMailWitty call in a function that's shared by both. For example:

STRING echeckbasemailpath := "site::repository/utwente-data/mailtemplates/echeck/";

PUBLIC OBJECT FUNCTION GetEcheckNotFoundMaill(STRING mail, RECORD options)
  options := ValidateOptions([ url := "https://www.utwente.nl/"
                             , programmetitle := "[programmetitle]"
                             ], options);
  OBJECT composer := PrepareMailWitty(`${echeckbasemailpath}formnotfound.html.witty`);
  composer->mailto := [ STRING(mail) ];
  composer->mergerecord := options;
  RETURN composer;

Then, it's a simple matter of invoking the emailtest dialog in a tollium action:

LOADLIB "mod::system/lib/dialogs.whlib";

MACRO DoPreviewNotFound()
  RunEmailTestDialog(this, GetEcheckNotFoundMaill("user@example.net", DEFAULT RECORD));

A dialog will open which will automatically refresh itself if you update the underlying witty files, similar to this:

Other features