source: trunk/lib/Epoll/View/Mail.pm @ 377

Last change on this file since 377 was 377, checked in by misc, 14 years ago
  • show a error message when the mail server is down
File size: 1.6 KB
Line 
1package Epoll::View::Mail;
2
3use strict;
4use base 'Catalyst::View::TT';
5use Mail::Mailer;
6use Epoll;
7use Epoll::DB;
8
9__PACKAGE__->config(
10    TEMPLATE_EXTENSION => '.tt',
11    INCLUDE_PATH => Epoll->path_to( 'root', 'mail' ),
12    PLUGIN_BASE => 'Epoll::Template::Plugin',
13    PRE_PROCESS => [ 'includes/loc.tt', ],
14);
15
16=head1 NAME
17
18Epoll::View::TT - TT View for Epoll
19
20=head1 DESCRIPTION
21
22TT View for Epoll.
23
24=cut
25
26sub render {
27    my ($self, $c, $template, $args) = @_;
28
29    my ($locale) = split(';', $c->req->header('Accept-Language') || '');
30    if (my $plocale = ($c->req->param('locale')|| $c->session->{'locale'})) {
31        $c->session->{'locale'} = $locale = $plocale;
32    }
33    $c->languages($locale ? [ $locale ] : '');
34    $c->stash->{locale} = $locale;
35
36    $ENV{MAILADDRESS} = $args->{From};
37    my $mailer = new Mail::Mailer 'smtp', Server => (Epoll->config->{smtp} || 'localhost');
38    eval { 
39        $mailer->open({
40            (map { $_ => $args->{$_} } grep { $_ !~ /^(mail)$/ } keys %{ $args || {}}),
41            'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
42            'Content-Transfer-Encoding' => '8bit',
43            'X-Epoll-version' => $Epoll::DB::VERSION,
44        });
45        print $mailer
46        Catalyst::View::TT::render($self, $c, $template, { %{ $args->{mail} || {} }, c => $c });
47        $mailer->close;
48    };
49    if ($@) {
50        $c->stash->{mail_error} = $@;
51    }   
52}
53
54=head1 SEE ALSO
55
56L<Epoll>
57
58=head1 AUTHOR
59
60Thauvin Olivier
61
62=head1 LICENSE
63
64This library is free software, you can redistribute it and/or modify
65it under the same terms as Perl itself or CeCILL.
66
67=cut
68
691;
Note: See TracBrowser for help on using the repository browser.