Commit | Line | Data |
5a5a0df4 |
1 | package Catalyst::Plugin::Email; |
2 | |
3 | use strict; |
4 | use Email::Send; |
5 | use Email::MIME; |
6 | use Email::MIME::Creator; |
7 | |
8 | our $VERSION = '0.03'; |
9 | |
10 | =head1 NAME |
11 | |
12 | Catalyst::Plugin::Email - Send emails with Catalyst |
13 | |
14 | =head1 SYNOPSIS |
15 | |
16 | use Catalyst 'Email'; |
17 | |
18 | __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/]; |
19 | |
20 | $c->email( |
21 | header => [ |
22 | From => 'sri@oook.de', |
23 | To => 'sri@cpan.org', |
24 | Subject => 'Hello!' |
25 | ], |
26 | body => 'Hello sri' |
27 | ); |
28 | |
29 | =head1 DESCRIPTION |
30 | |
31 | Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>. |
32 | |
33 | =head2 METHODS |
34 | |
35 | =head3 email |
36 | |
37 | =cut |
38 | |
39 | sub email { |
40 | my $c = shift; |
41 | my $email = $_[1] ? {@_} : $_[0]; |
42 | $email = Email::MIME->create(%$email); |
43 | my $args = $c->config->{email} || []; |
44 | my @args = @{$args}; |
45 | my $class; |
46 | unless ( $class = shift @args ) { |
47 | $class = 'SMTP'; |
48 | unshift @args, 'localhost'; |
49 | } |
50 | send $class => $email, @args; |
51 | } |
52 | |
53 | =head1 SEE ALSO |
54 | |
55 | L<Catalyst>. |
56 | |
57 | =head1 AUTHOR |
58 | |
59 | Sebastian Riedel, C<sri@cpan.org> |
60 | |
61 | =head1 COPYRIGHT |
62 | |
1ab6815b |
63 | This program is free software, you can redistribute it and/or modify it |
64 | under the same terms as Perl itself. |
5a5a0df4 |
65 | |
66 | =cut |
67 | |
68 | 1; |