|
Lines 34-39
use Koha::DateUtils;
Link Here
|
| 34 |
use Date::Calc qw( Add_Delta_Days ); |
34 |
use Date::Calc qw( Add_Delta_Days ); |
| 35 |
use Encode; |
35 |
use Encode; |
| 36 |
use Carp; |
36 |
use Carp; |
|
|
37 |
use Koha::Email; |
| 37 |
|
38 |
|
| 38 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
39 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
| 39 |
|
40 |
|
|
Lines 262-272
sub SendAlerts {
Link Here
|
| 262 |
# find the list of borrowers to alert |
263 |
# find the list of borrowers to alert |
| 263 |
my $alerts = getalert( '', 'issue', $externalid ); |
264 |
my $alerts = getalert( '', 'issue', $externalid ); |
| 264 |
foreach (@$alerts) { |
265 |
foreach (@$alerts) { |
| 265 |
|
|
|
| 266 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
266 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
| 267 |
my $email = $borinfo->{email} or next; |
267 |
my $email = $borinfo->{email} or next; |
| 268 |
|
268 |
|
| 269 |
# warn "sending issues..."; |
269 |
# warn "sending issues..."; |
| 270 |
my $userenv = C4::Context->userenv; |
270 |
my $userenv = C4::Context->userenv; |
| 271 |
my $branchdetails = GetBranchDetail($_->{'branchcode'}); |
271 |
my $branchdetails = GetBranchDetail($_->{'branchcode'}); |
| 272 |
my $letter = GetPreparedLetter ( |
272 |
my $letter = GetPreparedLetter ( |
|
Lines 283-295
sub SendAlerts {
Link Here
|
| 283 |
) or return; |
283 |
) or return; |
| 284 |
|
284 |
|
| 285 |
# ... then send mail |
285 |
# ... then send mail |
| 286 |
my %mail = ( |
286 |
my $message = Koha::Email->new(); |
| 287 |
To => $email, |
287 |
my %mail = $message->create_message_headers( |
| 288 |
From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), |
288 |
{ |
| 289 |
Subject => Encode::encode( "utf8", "" . $letter->{title} ), |
289 |
to => $email, |
| 290 |
Message => Encode::encode( "utf8", "" . $letter->{content} ), |
290 |
from => $branchdetails->{'branchemail'}, |
| 291 |
'Content-Type' => 'text/plain; charset="utf8"', |
291 |
replyto => $branchdetails->{'branchreplyto'}, |
| 292 |
); |
292 |
sender => $branchdetails->{'branchreturnpath'}, |
|
|
293 |
subject => Encode::encode( "utf8", "" . $letter->{title} ), |
| 294 |
message => |
| 295 |
Encode::encode( "utf8", "" . $letter->{content} ), |
| 296 |
contenttype => 'text/plain; charset="utf8"', |
| 297 |
|
| 298 |
} |
| 299 |
); |
| 293 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
300 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 294 |
} |
301 |
} |
| 295 |
} |
302 |
} |
|
Lines 368-373
sub SendAlerts {
Link Here
|
| 368 |
Message => Encode::encode( "utf8", "" . $letter->{content} ), |
375 |
Message => Encode::encode( "utf8", "" . $letter->{content} ), |
| 369 |
'Content-Type' => 'text/plain; charset="utf8"', |
376 |
'Content-Type' => 'text/plain; charset="utf8"', |
| 370 |
); |
377 |
); |
|
|
378 |
$mail{'Reply-to'} = C4::Context->preference('ReplytoDefault') |
| 379 |
if C4::Context->preference('ReplytoDefault'); |
| 380 |
$mail{'Sender'} = C4::Context->preference('ReturnpathDefault') |
| 381 |
if C4::Context->preference('ReturnpathDefault'); |
| 382 |
|
| 371 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
383 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 372 |
|
384 |
|
| 373 |
logaction( |
385 |
logaction( |
|
Lines 396-409
sub SendAlerts {
Link Here
|
| 396 |
substitute => { 'borrowers.password' => $externalid->{'password'} }, |
408 |
substitute => { 'borrowers.password' => $externalid->{'password'} }, |
| 397 |
want_librarian => 1, |
409 |
want_librarian => 1, |
| 398 |
) or return; |
410 |
) or return; |
| 399 |
|
|
|
| 400 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
411 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
| 401 |
my %mail = ( |
412 |
my $email = Koha::Email->new(); |
| 402 |
To => $externalid->{'emailaddr'}, |
413 |
my %mail = $email->create_message_headers( |
| 403 |
From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), |
414 |
{ |
| 404 |
Subject => Encode::encode( "utf8", $letter->{'title'} ), |
415 |
to => $externalid->{'emailaddr'}, |
| 405 |
Message => Encode::encode( "utf8", $letter->{'content'} ), |
416 |
from => $branchdetails->{'branchemail'}, |
| 406 |
'Content-Type' => 'text/plain; charset="utf8"', |
417 |
replyto => $branchdetails->{'branchreplyto'}, |
|
|
418 |
sender => $branchdetails->{'branchreturnpath'}, |
| 419 |
subject => Encode::encode( "utf8", "" . $letter->{'title'} ), |
| 420 |
message => Encode::encode( "utf8", "" . $letter->{'content'} ), |
| 421 |
contenttype => 'text/plain; charset="utf8"' |
| 422 |
} |
| 407 |
); |
423 |
); |
| 408 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
424 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 409 |
} |
425 |
} |
|
Lines 969-985
sub _send_message_by_email {
Link Here
|
| 969 |
my $content = encode('utf8', $message->{'content'}); |
985 |
my $content = encode('utf8', $message->{'content'}); |
| 970 |
my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"'; |
986 |
my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"'; |
| 971 |
my $is_html = $content_type =~ m/html/io; |
987 |
my $is_html = $content_type =~ m/html/io; |
| 972 |
|
988 |
my $branch_email = undef; |
| 973 |
my $branch_email = ( $member ) ? GetBranchDetail( $member->{'branchcode'} )->{'branchemail'} : undef; |
989 |
my $branch_replyto = undef; |
| 974 |
|
990 |
my $branch_returnpath = undef; |
| 975 |
my %sendmail_params = ( |
991 |
if ($member){ |
| 976 |
To => $to_address, |
992 |
my $branchdetail = GetBranchDetail( $member->{'branchcode'} ); |
| 977 |
From => $message->{'from_address'} || $branch_email || C4::Context->preference('KohaAdminEmailAddress'), |
993 |
$branch_email = $branchdetail->{'branchemail'}; |
| 978 |
Subject => $subject, |
994 |
$branch_replyto = $branchdetail->{'branchreplyto'}; |
| 979 |
charset => 'utf8', |
995 |
$branch_returnpath = $branchdetail->{'branchreturnpath'}; |
| 980 |
Message => $is_html ? _wrap_html($content, $subject) : $content, |
996 |
} |
| 981 |
'content-type' => $content_type, |
997 |
my $email = Koha::Email->new(); |
|
|
998 |
my %sendmail_params = $email->create_message_headers( |
| 999 |
{ |
| 1000 |
to => $to_address, |
| 1001 |
from => $message->{'from_address'} || $branch_email, |
| 1002 |
replyto => $branch_replyto, |
| 1003 |
sender => $branch_returnpath, |
| 1004 |
subject => $subject, |
| 1005 |
message => $is_html ? _wrap_html( $content, $subject ) : $content, |
| 1006 |
contenttype => $content_type |
| 1007 |
} |
| 982 |
); |
1008 |
); |
|
|
1009 |
|
| 983 |
$sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; |
1010 |
$sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; |
| 984 |
if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) { |
1011 |
if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) { |
| 985 |
$sendmail_params{ Bcc } = $bcc; |
1012 |
$sendmail_params{ Bcc } = $bcc; |
| 986 |
- |
|
|