The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Catalyst::View::Email::Template - Send Templated Email from Catalyst

SYNOPSIS

Sends Templated mail, based upon your Default View. Will capture the output of the rendering path, slurps in based on mime-types and assembles a multi-part email and sends it out.

CONFIGURATION

    View::Email::Template:
        # Set it up so if you have multiple parts, they're alternatives.
        # This is on the top-level message, not the individual parts.
        content_type: multipart/alternative
        # Optional prefix to look somewhere under the existing configured
        # template  paths.
        template_prefix: email
        # Where to look in the stash for the email information
        stash_key: email
        # Setup how to send the email
        sender:
            method:     SMTP
            host:       smtp.myhost.com
            username:   username
            password:   password

SENDING EMAIL

Sending email is just setting up your stash key, and forwarding to the view.

    $c->stash->{email} = {
        to      => 'jshirley@gmail.com',
        from    => 'no-reply@foobar.com',
        subject => 'I am a Catalyst generated email',
        # Specify which templates to include
        templates => [
            qw{text_plain/test.tt},
            qw{text_html/test.tt}
        ]
    };
    $c->forward('View::Email::Template');

If it fails $c->error will have the error message.

TODO

ATTACHMENTS

There needs to be a method to support attachments. What I am thinking is something along these lines:

    attachments => [
        # Set the body to a file handle object, specify content_type and
        # the file name. (name is what it is sent at, not the file)
        { body => $fh, name => "foo.pdf", content_type => "application/pdf" },
        # Or, specify a filename that is added, and hey, encoding!
        { filename => "foo.gif", name => "foo.gif", content_type => "application/pdf", encoding => "quoted-printable" },
        # Or, just a path to a file, and do some guesswork for the content type
        "/path/to/somefile.pdf",
    ]

SEE ALSO

Catalyst::View::Email - Send plain boring emails with Catalyst

Catalyst::Manual - The Catalyst Manual

Catalyst::Manual::Cookbook - The Catalyst Cookbook

AUTHORS

J. Shirley <jshirley@gmail.com>

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.