1 |
dpavlin |
1134 |
package App::RoomReservation::Email; |
2 |
|
|
use Moose::Role; |
3 |
|
|
|
4 |
|
|
use Email::Sender::Simple qw(sendmail); |
5 |
|
|
use Email::Simple; |
6 |
|
|
use Email::Simple::Creator; |
7 |
|
|
|
8 |
|
|
requires 'dbh'; |
9 |
|
|
|
10 |
|
|
sub send { |
11 |
|
|
my ($self, $email, $subject, $body) = @_; |
12 |
|
|
|
13 |
|
|
my $sth = $self->dbh->prepare(qq{ |
14 |
|
|
select ime,prezime from reservation where email = ? |
15 |
|
|
}); |
16 |
|
|
|
17 |
|
|
$sth->execute($email); |
18 |
|
|
|
19 |
dpavlin |
1165 |
die qq|<error>Can't find registered user with e-mail $email| unless $sth->rows == 1; |
20 |
dpavlin |
1134 |
|
21 |
|
|
my ($ime,$prezime) = $sth->fetchrow_array; |
22 |
|
|
my $to = qq{"$ime $prezime" <$email>}; |
23 |
|
|
|
24 |
|
|
$body =~ s{^\s+}{}gm; # strip whitespace at beginning of line |
25 |
dpavlin |
1166 |
$body =~ s{<br>}{\n}gs; |
26 |
dpavlin |
1134 |
$body =~ s{<[^>]+/?>}{}gs; # strip html |
27 |
|
|
|
28 |
|
|
my $m = Email::Simple->create( |
29 |
|
|
header => [ |
30 |
|
|
To => $to, |
31 |
dpavlin |
1173 |
From => '<predavanje_psih@ffzg.hr>', |
32 |
dpavlin |
1134 |
Subject => $subject, |
33 |
dpavlin |
1181 |
'X-Mailer' => __PACKAGE__, |
34 |
|
|
'MIME-Version' => '1.0', |
35 |
|
|
'Content-Type' => 'text/plain; charset=utf-8', |
36 |
dpavlin |
1134 |
], |
37 |
|
|
body => $body, |
38 |
|
|
); |
39 |
|
|
|
40 |
|
|
sendmail($m); |
41 |
|
|
|
42 |
|
|
warn "# send to $to\n$body\n"; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
no Moose::Role; |
46 |
|
|
|
47 |
|
|
1; |