1 |
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 |
die "can't find registered user with e-mail $email" unless $sth->rows == 1; |
20 |
|
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 |
$body =~ s{<[^>]+/?>}{}gs; # strip html |
26 |
|
27 |
my $m = Email::Simple->create( |
28 |
header => [ |
29 |
To => $to, |
30 |
From => '"Room Reservation" <room-reservation@rot13.org>', |
31 |
Subject => $subject, |
32 |
], |
33 |
body => $body, |
34 |
); |
35 |
|
36 |
sendmail($m); |
37 |
|
38 |
warn "# send to $to\n$body\n"; |
39 |
} |
40 |
|
41 |
no Moose::Role; |
42 |
|
43 |
1; |