Last active
June 26, 2020 17:35
-
-
Save tommybutler/7b92e52b07a608de0c303f6b1ca23482 to your computer and use it in GitHub Desktop.
Email a PDF with Mojolicious::Plugin::Mail, and PDF::WebKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $pdf = 'my-html-template-for-conversion-to-pdf'; # needs to be a .html.ep template | |
my $mail = 'my-template-for-the-html-email'; # needs to be a .mail.ep template | |
$pdf = $c->render_to_string( $pdf )->to_string(); | |
$pdf = PDF::WebKit->new( \$pdf, %pdf_opt )->to_pdf(); # see PDF::WebKit documentation for details | |
$c->mail | |
( | |
mail => | |
{ | |
To => $recipients, | |
From => $from, | |
ReplyTo => $reply_to, | |
Type => 'multipart/mixed', | |
Subject => $mail_subject, | |
}, | |
attach => | |
[ | |
{ | |
Type => 'text/html', | |
Data => $c->render_mail( $mail ), | |
}, | |
{ | |
Type => 'application/pdf', | |
Filename => 'my-pdf-file.pdf', | |
Disposition => 'attachment', | |
Data => $pdf, | |
}, | |
] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment