|
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 356-361
sub SendAlerts {
Link Here
|
| 356 |
Message => Encode::encode( "utf8", "" . $letter->{content} ), |
363 |
Message => Encode::encode( "utf8", "" . $letter->{content} ), |
| 357 |
'Content-Type' => 'text/plain; charset="utf8"', |
364 |
'Content-Type' => 'text/plain; charset="utf8"', |
| 358 |
); |
365 |
); |
|
|
366 |
$mail{'Reply-to'} = C4::Context->preference('ReplytoDefault') |
| 367 |
if C4::Context->preference('ReplytoDefault'); |
| 368 |
$mail{'Sender'} = C4::Context->preference('ReturnpathDefault') |
| 369 |
if C4::Context->preference('ReturnpathDefault'); |
| 370 |
|
| 359 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
371 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 360 |
|
372 |
|
| 361 |
logaction( |
373 |
logaction( |
|
Lines 384-397
sub SendAlerts {
Link Here
|
| 384 |
substitute => { 'borrowers.password' => $externalid->{'password'} }, |
396 |
substitute => { 'borrowers.password' => $externalid->{'password'} }, |
| 385 |
want_librarian => 1, |
397 |
want_librarian => 1, |
| 386 |
) or return; |
398 |
) or return; |
| 387 |
|
|
|
| 388 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
399 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
| 389 |
my %mail = ( |
400 |
my $email = Koha::Email->new(); |
| 390 |
To => $externalid->{'emailaddr'}, |
401 |
my %mail = $email->create_message_headers( |
| 391 |
From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), |
402 |
{ |
| 392 |
Subject => Encode::encode( "utf8", $letter->{'title'} ), |
403 |
to => $externalid->{'emailaddr'}, |
| 393 |
Message => Encode::encode( "utf8", $letter->{'content'} ), |
404 |
from => $branchdetails->{'branchemail'}, |
| 394 |
'Content-Type' => 'text/plain; charset="utf8"', |
405 |
replyto => $branchdetails->{'branchreplyto'}, |
|
|
406 |
sender => $branchdetails->{'branchreturnpath'}, |
| 407 |
subject => Encode::encode( "utf8", "" . $letter->{'title'} ), |
| 408 |
message => Encode::encode( "utf8", "" . $letter->{'content'} ), |
| 409 |
contenttype => 'text/plain; charset="utf8"' |
| 410 |
} |
| 395 |
); |
411 |
); |
| 396 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
412 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 397 |
} |
413 |
} |
|
Lines 949-965
sub _send_message_by_email {
Link Here
|
| 949 |
my $content = encode('utf8', $message->{'content'}); |
965 |
my $content = encode('utf8', $message->{'content'}); |
| 950 |
my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"'; |
966 |
my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"'; |
| 951 |
my $is_html = $content_type =~ m/html/io; |
967 |
my $is_html = $content_type =~ m/html/io; |
| 952 |
|
968 |
my $branch_email = undef; |
| 953 |
my $branch_email = ( $member ) ? GetBranchDetail( $member->{'branchcode'} )->{'branchemail'} : undef; |
969 |
my $branch_replyto = undef; |
| 954 |
|
970 |
my $branch_returnpath = undef; |
| 955 |
my %sendmail_params = ( |
971 |
if ($member){ |
| 956 |
To => $to_address, |
972 |
my $branchdetail = GetBranchDetail( $member->{'branchcode'} ); |
| 957 |
From => $message->{'from_address'} || $branch_email || C4::Context->preference('KohaAdminEmailAddress'), |
973 |
$branch_email = $branchdetail->{'branchemail'}; |
| 958 |
Subject => $subject, |
974 |
$branch_replyto = $branchdetail->{'branchreplyto'}; |
| 959 |
charset => 'utf8', |
975 |
$branch_returnpath = $branchdetail->{'branchreturnpath'}; |
| 960 |
Message => $is_html ? _wrap_html($content, $subject) : $content, |
976 |
} |
| 961 |
'content-type' => $content_type, |
977 |
my $email = Koha::Email->new(); |
|
|
978 |
my %sendmail_params = $email->create_message_headers( |
| 979 |
{ |
| 980 |
to => $to_address, |
| 981 |
from => $message->{'from_address'} || $branch_email, |
| 982 |
replyto => $branch_replyto, |
| 983 |
sender => $branch_returnpath, |
| 984 |
subject => $subject, |
| 985 |
message => $is_html ? _wrap_html( $content, $subject ) : $content, |
| 986 |
contenttype => $content_type |
| 987 |
} |
| 962 |
); |
988 |
); |
|
|
989 |
|
| 963 |
$sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; |
990 |
$sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; |
| 964 |
if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) { |
991 |
if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) { |
| 965 |
$sendmail_params{ Bcc } = $bcc; |
992 |
$sendmail_params{ Bcc } = $bcc; |
| 966 |
- |
|
|