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" ];
  outmail->QueueMailInWork();

with the following Wittytemplate:

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

Templates

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

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

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

Comments