Email::MIME::Kit - build messages from templates


version 2.091920


Achtung! Even though this is marked a version 2.000, it is not a stable, well-proven interface. It is a complete rewrite of a version-1 product that was used only internally. You may want to wait for this warning to go away before relying on this code in your production environment.

  -- rjbs, 2009-01-24


  use Email::MIME::Kit;

  my $kit = Email::MIME::Kit->new({ source => 'mkits/sample.mkit' });

  my $email = $kit->assemble({
    account           => $new_signup,
    verification_code => $token,
    ... and any other template vars ...

  $transport->send($email, { ... });


Email::MIME::Kit is a templating system for email messages. Instead of trying to be yet another templating system for chunks of text, it makes it easy to build complete email messages.

It handles the construction of multipart messages, text and HTML alternatives, attachments, interpart linking, string encoding, and parameter validation.

Although nearly every part of Email::MIME::Kit is a replaceable component, the stock configuration is probably enough for most use. A message kit will be stored as a directory that might look like this:


The manifest file tells Email::MIME::Kit how to put it all together, and might look something like this:

    "renderer": "TT",
    "header": [
      { "From": "WY Corp <>" },
      { "Subject": "Welcome aboard, [% %]!" }
    "alternatives": [
      { "type": "text/plain", "path": "body.txt" },
        "type": "text/html",
        "path": "body.html",
        "container_type": "multipart/related",
        "attachments": [ { "type": "image/jpeg", "path": "logo.jpg" } ]

Please note: the assembly of HTML documents as multipart/related bodies will probably be simplified with an alternate assembler in the near future.

The above manifest would build a multipart alternative message. GUI mail clients would see a rendered HTML document with the logo graphic visible from the attachment. Text mail clients would see the plaintext.

Both the HTML and text parts would be rendered using the named renderer, which here is Template-Toolkit.

The message would be assembled and returned as an Email::MIME object, just as easily as suggested in the "SYNOPSIS" above.


This module is maintained by the Perl Email Project


This code was written in 2009 by Ricardo SIGNES. It was based on a previous implementation by Hans Dieter Pearcey written in 2006.

The development of this code was sponsored by Thanks, Pobox!


This software is copyright (c) 2009 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.