xMonk has asked for the wisdom of the Perl Monks concerning the following question:
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:
- The email is going to be HTML formatted with images.
- It will sometimes contain a separate file attachment.
- 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>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help generating an HTML mail with Email::MIME::Kit
by roboticus (Chancellor) on Sep 13, 2017 at 12:41 UTC | |
by xMonk (Initiate) on Sep 14, 2017 at 00:01 UTC | |
Re: Need help generating an HTML mail with Email::MIME::Kit
by xMonk (Initiate) on Sep 14, 2017 at 06:10 UTC | |
by afoken (Chancellor) on Sep 14, 2017 at 06:44 UTC |
Back to
Seekers of Perl Wisdom