Hi monks,

I've been working on a module for work and in one part of it I need to generate an email object using Email::MIME::Kit.

Here are my requirements:

  1. The email is going to be HTML formatted with images.
  2. It will sometimes contain a separate file attachment.
  3. I want the email to be generated from a scalar or hash containing the template.

I've been looking for docs/tutorials/anything to help me with this for > 1 day now and I'm so frustrated...

If anyone can help me with this, I'd be eternally thankful!

Here's my code for the sub so far:

sub create_mime_email { # Parse arguments my $template_path = shift or die q~No template file found in provide +d path~; my $manifest_reader = shift // 'JSON'; # Load required modules use Email::MIME::Kit; my $kit = Email::MIME::Kit->new({ source => $template_path, manifest_reader => $manifest_reader, }); my $email = $kit->assemble(); return $email; }

... And the template code:

{ "header": [ { "Subject": "MIME e-mail test" }, { "From": "John Doe <john@gmail.com>" }, { "To": "Jane Doe <jane@gmail.com>" } ], "alternatives": [ { "container_type": "multipart/related", "type": "text/html", "path": "better-alternative.html", "attributes": { "charset": "utf-8" }, "attachments": [ { "type": "image/jpeg", "path": "logo.jpg" } ] } ], "attachments": [ { "type": "application/pdf", "path": "bogus-report.pdf", "attributes": { "filename": "report.pdf" } } ] }

... And the contents of the html template file:

<html> <body> Hello World! <img src='cid:[% cid_for("logo.jpg") %]' /> </body> </html>

In reply to Need help generating an HTML mail with Email::MIME::Kit by xMonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.