Cataly...emplate(3pm)
β¨ NAME β¨
Catalyst::View::Email::Template β it's giving Send Templated Email from Catalyst π
okay so real talk: this is a 3pm perl manpage from the User Contributed Perl Documentation, and its whole personality is making your Catalyst app send templated email like it's nothing. no cap. π«Ά
π¦ SYNOPSIS π¦
It sends templated mail, based upon your default view. Basically it grabs the output of the rendering path, slurps it in based on mime-types, and then assembles a multi-part email using Email::MIME::Creator and sends it out. it's giving "I do all the assembling, you just vibe." β¨
π CONFIGURATION π
WARNING: since version 0.10 the configuration options slightly changed! not me warning you, this is literally in the docs π
Use the helper to create your view:
$ script/myapp_create.pl view Email::Template Email::Template
For basic configuration look at "CONFIGURATION" in Catalyst::View::Email.
In your app configuration (example in YAML):
View::Email::Template:
# Optional prefix to look somewhere under the existing configured
# template paths.
# Default: none
template_prefix: email
# Define the defaults for the mail
default:
# Defines the default view used to render the templates.
# If none is specified neither here nor in the stash
# Catalysts default view is used.
# Warning: if you don't tell Catalyst explicit which of your views should
# be its default one, C::V::Email::Template may choose the wrong one!
view: TT
So like, breaking down the vibes: πΈ
template_prefixβ an optional prefix so you can look somewhere under the existing configured template paths. Default: none.defaultβ the defaults for the mail.viewβ the default view used to render the templates. If none is specified, neither here nor in the stash, then Catalyst's default view gets used.
Warning: if you don't tell Catalyst explicitly which of your views should be its default one, C::V::Email::Template may choose the wrong one! main character energy gone wrong, bestie, please be specific π
π SENDING EMAIL π
Sending email works just like for Catalyst::View::Email, but instead of the body you specify the template, and then you forward to your Email::Template view:
sub controller : Private {
my ( $self, $c ) = @_;
$c->stash->{email} = {
to => 'jshirley@gmail.com',
cc => 'abraxxa@cpan.org',
from => 'no-reply@foobar.com',
subject => 'I am a Catalyst generated email',
template => 'test.tt',
content_type => 'multipart/alternative'
};
$c->forward( $c->view('Email::Template') );
}
Alternatively, if you want more control over your templates you can use the following idiom to override the defaults. If charset and encoding are given, the body becomes properly encoded. π
templates => [
{
template => 'email/test.html.tt',
content_type => 'text/html',
charset => 'utf-8',
encoding => 'quoted-printable',
view => 'TT',
},
{
template => 'email/test.plain.mason',
content_type => 'text/plain',
charset => 'utf-8',
encoding => 'quoted-printable',
view => 'Mason',
}
]
π HANDLING ERRORS π
See "HANDLING ERRORS" in Catalyst::View::Email. yeah, it's a whole other page, go read it, iykyk π«Ά
π§ METHODS π§
generate_part
Generates a MIME part to include in the email. Since the email is template based, every template piece is a separate part that gets included in the email. it's giving "one part per vibe" β¨
process
The process method is called when the view is dispatched to. This creates the multipart message and then sends the message contents off to Catalyst::View::Email for processing, which in turn hands off to Email::Sender::Simple. iconic relay race honestly πββοΈ
π TODO π
ATTACHMENTS
There needs to be a method to support attachments. What the author is 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",
]
not shipped yet, bestie, this is a wishlist π
π₯ SEE ALSO π₯
Catalyst::View::Emailβ Send plain boring emails with CatalystCatalyst::Manualβ The Catalyst ManualCatalyst::Manual::Cookbookβ The Catalyst Cookbook
π AUTHORS π
- J. Shirley <jshirley@gmail.com>
- Simon Elliott <cpan@browsing.co.uk>
- Alexander Hartmaier <abraxxa@cpan.org>
π LICENSE π
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. slay, open source queen π
and that's the whole page, babe β perl v5.38.2, dated 2024-03-04, from the Cataly...emplate(3pm) file. go forth and send emails πβ¨
π¦ where this page comes from
- debian trixie: libcatalyst-view-email-perl 0.36-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatalyst-view-email-perl 0.36-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-view-email-perl 0.36-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-view-email-perl 0.36-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms