[dancer-users] How to use HTML template as body to an Email?

Rick Leir richard.leir at canadiana.ca
Mon Feb 1 14:12:53 GMT 2016


I have not been using multipart so far, though I may do in the future. HTH.



use Email::MIME::CreateHTML;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP qw();
...
    my $email_body = template(
        $tt,
        \%fields,
    );
    # produce an Email::Abstract compatible message object,
    my $email = Email::MIME->create_html(
        header =>
        [
            From    => $fields{email_from},
            To      => $fields{email},
            Subject => $fields{email_subject},
        ],
        body => $email_body,
    );

    try {
        sendmail($email,
                 {
                     from => $fields{email_from},
                     transport => Email::Sender::Transport::SMTP->new({
                         host => config->{smtp_server},
                         port => config->{smtp_port},
                     }),
                 }
         );
    } catch {
..


[testemail:37988] error @2016-01-26 14:46:09> Route exception: Could not
> send email can't build entity: no body, and not multipart
>
> I am getting a multipart warning because I didn't specify "multipart =>
> 'related'" in email function. I believe, Dancer2 requires "multipart" to
> be set to "related" when you want to send HTML emails.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20160201/8059341f/attachment.html>


More information about the dancer-users mailing list