1Email(3) User Contributed Perl Documentation Email(3)
2
3
4
6 Catalyst::Plugin::Email - Send emails with Catalyst
7
9 use Catalyst 'Email';
10
11 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
12
13 $c->email(
14 header => [
15 From => 'sri@oook.de',
16 To => 'sri@cpan.org',
17 Subject => 'Hello!'
18 ],
19 body => 'Hello sri'
20 );
21
23 Send emails with Catalyst and Email::Send and Email::MIME::Creator.
24
26 "config" accepts the same options as Email::Send.
27
28 To send using the system's "sendmail" program, set "config" like so:
29
30 __PACKAGE__->config->{email} = ['Sendmail'];
31
32 To send using authenticated SMTP:
33
34 __PACKAGE__->config->{email} = [
35 'SMTP',
36 'smtp.myhost.com',
37 username => $USERNAME,
38 password => $PASSWORD,
39 ];
40
41 For different methods of sending emails, and appropriate "config"
42 options, see Email::Send::NNTP, Email::Send::Qmail, Email::Send::SMTP
43 and Email::Send::Sendmail.
44
46 email
47 "email()" accepts the same arguments as Email::MIME::Creator's
48 "create()".
49
50 $c->email(
51 header => [
52 To => 'me@localhost',
53 Subject => 'A TT Email',
54 ],
55 body => $c->subreq( '/render_email' ),
56 );
57
58 To send a multipart message, include a "parts" argument containing an
59 arrayref of Email::MIME objects.
60
61 my @parts = (
62 Email::MIME->create(
63 attributes => {
64 content_type => 'application/pdf',
65 encoding => 'quoted-printable',
66 name => 'report.pdf',
67 },
68 body => $FILE_DATA,
69 ),
70 Email::MIME->create(
71 attributes => {
72 content_type => 'text/plain',
73 disposition => 'attachment',
74 charset => 'US-ASCII',
75 },
76 body => $c->subreq( '/render_email' ),
77 ),
78 );
79
80 $c->email(
81 header => [
82 To => 'me@localhost',
83 Subject => 'A TT Email',
84 ],
85 parts => \@parts,
86 );
87
89 A common practice is to handle emails using the same template language
90 used for HTML pages. If your view supports the 'render' method (Like
91 the TT view does), you just set the body like this:
92 $c->email(
93 header => [
94 To => 'me@localhost',
95 Subject => 'A TT Email',
96 ],
97 body => $c->view('TT')->render($c,'mytemplate.tt'),
98 }
99
100 If your view doesn't support render, you can just forward to it, then
101 reset the body like this:
102
103 sub send_email : Local {
104 my ( $self, $c ) = @_;
105 {
106 local $c->stash->{names} = [ qw/andyg sri mst/ ],
107 local $c->stash->{template}= 'mytemplate.tt';
108 $c->forward($c->view('MyView'));
109 $c->email(
110 header => [
111 To => 'me@localhost',
112 Subject => 'A TT Email',
113 ],
114 body => $c->res->body,
115 );
116 $c->res->body(undef);
117 }
118 }
119
120 And the template:
121
122 [%- FOREACH name IN names -%]
123 Hi, [% name %]!
124 [%- END -%]
125
126 --
127 Regards,
128 Us
129
130 Output:
131
132 Hi, andyg!
133 Hi, sri!
134 Hi, mst!
135
136 --
137 Regards,
138 Us
139
141 Catalyst, Catalyst::Plugin::SubRequest, Email::Send,
142 Email::MIME::Creator
143
145 Sebastian Riedel, "sri@cpan.org" Andy Grundman Carl Franks Marcus
146 Ramberg "mramberg@cpan.org"
147
149 This program is free software, you can redistribute it and/or modify it
150 under the same terms as Perl itself.
151
152
153
154perl v5.12.0 2006-12-31 Email(3)