started work to add pod tests to all submodules.
[catagits/Catalyst-Plugin-Email.git] / Email.pm
CommitLineData
5a5a0df4 1package Catalyst::Plugin::Email;
2
3use strict;
4use Email::Send;
5use Email::MIME;
6use Email::MIME::Creator;
7
8our $VERSION = '0.03';
9
10=head1 NAME
11
12Catalyst::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
31Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
32
33=head2 METHODS
34
35=head3 email
36
37=cut
38
39sub 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
55L<Catalyst>.
56
57=head1 AUTHOR
58
59Sebastian Riedel, C<sri@cpan.org>
60
61=head1 COPYRIGHT
62
1ab6815b 63This program is free software, you can redistribute it and/or modify it
64under the same terms as Perl itself.
5a5a0df4 65
66=cut
67
681;