mail-template

Provides mechanisms for generating mails based on templates


This crate provides a general interface for using template engine with the mail crate.

It's core is the TemplateEngine trait which can be implemented to bind a template engine. When rendering a template the template engine implementing the TemplateEngine trait will produce a number of (wrapped) Resource instances representing the alternate bodies of amail as well as a number of additional Resources used for embedded content (e.g. logoimages) and attachments. This crate then takes this parts and composes a multipart mime mail from it.

Template Engine implementations

A mail template engine has to do more then just taking a single text template (e.g. a handlebars template) and produce some output using string magic. It has to:

  1. consider alternate bodies, so it should render at last two "text templates" (one text/plain, one html)

  2. consider which additional embeddings/attachments should be included (all in the given template data are included, but you might add additional ones, e.g. some logo image)

As such text template engines like Handle bar can not directly be bound to the TemplateEngine trait.

For using text template engine it's recommended to use the mail-template-render-engine (also exposed through the mail facade) which implements this overhead for any engine which can "just" render some text and provides default bindings to some common template engines (e.g. Handlebars).

Derive

This crate requires template data to implement InspectEmbeddedResources which combined with some typing/generic design decisions allows to bind not just to template engines which use serialization to access template data but also to such which use static typing (like askama).

As such it re-exports the InspectEmbeddedResources derive from mail-derive. Note that if you use the mail facade it also does re-export the derive.

Features

Example

rust

Road Map

The current implementation has a number of limitations which should be lifted with future versions:

Also there are some parts which are likely to change:

Documentation

Documentation can be viewed on docs.rs. (once published)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.