2 Catalyst::View::Email - Send Email from Catalyst
5 This module sends out emails from a stash key specified in the
6 configuration settings.
9 WARNING: since version 0.10 the configuration options slightly changed!
11 Use the helper to create your View:
13 $ script/myapp_create.pl view Email Email
15 In your app configuration:
19 # Where to look in the stash for the email information.
20 # 'email' is the default, so you don't have to specify it.
22 # Define the defaults for the mail
24 # Defines the default content type (mime type). Mandatory
25 content_type => 'text/plain',
26 # Defines the default charset for every MIME part with the
28 # According to RFC2049 a MIME part without a charset should
29 # be treated as US-ASCII by the mail client.
30 # If the charset is not set it won't be set for all MIME parts
31 # without an overridden one.
35 # Setup how to send the email
36 # all those options are passed directly to Email::Sender::Simple
38 # if mailer doesn't start with Email::Sender::Simple::Transport::,
39 # then this is prepended.
41 # mailer_args is passed directly into Email::Sender::Simple
43 Host => 'smtp.example.com', # defaults to localhost
44 username => 'username',
45 password => 'password',
52 If you use SMTP and don't specify host, it will default to localhost and
53 attempt delivery. This often means an email will sit in a queue and not
57 Sending email is just filling the stash and forwarding to the view:
59 sub controller : Private {
60 my ( $self, $c ) = @_;
62 $c->stash->{email} = {
63 to => 'jshirley@gmail.com',
64 cc => 'abraxxa@cpan.org',
65 from => 'no-reply@foobar.com',
66 subject => 'I am a Catalyst generated email',
67 body => 'Body Body Body',
70 $c->forward( $c->view('Email') );
73 Alternatively you can use a more raw interface and specify the headers
74 as an array reference like it is passed to Email::MIME::Creator. Note
75 that you may also mix both syntaxes if you like ours better but need to
76 specify additional header attributes. The attributes are appended to the
77 header array reference without overwriting contained ones.
79 $c->stash->{email} = {
81 To => 'jshirley@gmail.com',
82 Cc => 'abraxxa@cpan.org',
83 From => 'no-reply@foobar.com',
84 Subject => 'Note the capitalization differences',
86 body => qq{Ain't got no body, and nobody cares.},
91 content_type => 'text/plain',
92 disposition => 'attachment',
93 charset => 'US-ASCII',
95 body => qq{Got a body, but didn't get ahead.},
101 If the email fails to send, the view will die (throw an exception).
102 After your forward to the view, it is a good idea to check for errors:
104 $c->forward( $c->view('Email') );
106 if ( scalar( @{ $c->error } ) ) {
107 $c->error(0); # Reset the error condition if you need to
108 $c->response->body('Oh noes!');
110 $c->response->body('Email sent A-OK! (At least as far as we can tell)');
113 USING TEMPLATES FOR EMAIL
114 Now, it's no fun to just send out email using plain strings. Take a look
115 at Catalyst::View::Email::Template to see how you can use your favourite
116 template engine to render the mail body.
119 new Validates the base config and creates the Email::Sender::Simple
120 object for later use by process.
123 The process method does the actual processing when the view is
126 This method sets up the email parts and hands off to
127 Email::Sender::Simple to handle the actual email delivery.
129 setup_attributes($c, $attr)
130 Merge attributes with the configured defaults. You can override this
131 method to return a structure to pass into generate_message which
132 subsequently passes the return value of this method to
133 Email::MIME->create under the "attributes" key.
135 generate_message($c, $attr)
136 Generate a message part, which should be an Email::MIME object and
139 Takes the attributes, merges with the defaults as necessary and
140 returns a message object.
143 As with most things computer related, things break. Email even more so.
144 Typically any errors are going to come from using SMTP as your sending
145 method, which means that if you are having trouble the first place to
146 look is at Email::Sender::Transport::SMTP. This module is just a wrapper
147 for Email::Sender::Simple, so if you get an error on sending, it is
148 likely from there anyway.
150 If you are using SMTP and have troubles sending, whether it is
151 authentication or a very bland "Can't send" message, make sure that you
152 have Net::SMTP and, if applicable, Net::SMTP::SSL installed.
154 It is very simple to check that you can connect via Net::SMTP, and if
155 you do have sending errors the first thing to do is to write a simple
156 script that attempts to connect. If it works, it is probably something
157 in your configuration so double check there. If it doesn't, well, keep
158 modifying the script and/or your mail server configuration until it
162 Catalyst::View::Email::Template - Send fancy template emails with Cat
163 Catalyst::Manual - The Catalyst Manual
164 Catalyst::Manual::Cookbook - The Catalyst Cookbook
166 J. Shirley <jshirley@gmail.com>
168 Alexander Hartmaier <abraxxa@cpan.org>
175 Daniel Westermann-Clark
177 Simon Elliott <cpan@browsing.co.uk>
181 Lance Brown <lance@bearcircle.net>
183 Devin Austin <dhoss@cpan.org>
185 Chris Nehren <apeiron@cpan.org>
188 Copyright (c) 2007 - 2009 the Catalyst::View::Email "AUTHORS" and
189 "CONTRIBUTORS" as listed above.
192 This library is free software, you can redistribute it and/or modify it
193 under the same terms as Perl itself.