Lines 39-44
use Koha::SMS::Providers;
Link Here
|
39 |
|
39 |
|
40 |
use Koha::Email; |
40 |
use Koha::Email; |
41 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
41 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
|
|
42 |
use Email::Valid; |
42 |
|
43 |
|
43 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
|
45 |
|
Lines 403-409
sub SendAlerts {
Link Here
|
403 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
404 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
404 |
foreach (@$alerts) { |
405 |
foreach (@$alerts) { |
405 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
406 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
406 |
my $email = $borinfo->{email} or next; |
407 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
|
|
408 |
my $email = $sendAllEmailsTo; |
409 |
if (!($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo))){ |
410 |
$email = $borinfo->{email} or next; |
411 |
} |
407 |
|
412 |
|
408 |
# warn "sending issues..."; |
413 |
# warn "sending issues..."; |
409 |
my $userenv = C4::Context->userenv; |
414 |
my $userenv = C4::Context->userenv; |
Lines 517-526
sub SendAlerts {
Link Here
|
517 |
# Remove the order tag |
522 |
# Remove the order tag |
518 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
523 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
519 |
|
524 |
|
|
|
525 |
# SendAllEmailsTo system preference to override for testing |
526 |
my $emailsTo = join( ',', @email); |
527 |
my $emailsCC = join( ',', @cc); |
528 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
529 |
if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ) { |
530 |
$emailsTo = $sendAllEmailsTo; |
531 |
$emailsCC = ''; |
532 |
} |
533 |
|
520 |
# ... then send mail |
534 |
# ... then send mail |
521 |
my %mail = ( |
535 |
my %mail = ( |
522 |
To => join( ',', @email), |
536 |
To => $emailsTo, |
523 |
Cc => join( ',', @cc), |
537 |
Cc => $emailsCC, |
524 |
From => $userenv->{emailaddress}, |
538 |
From => $userenv->{emailaddress}, |
525 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
539 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
526 |
Message => $letter->{'is_html'} |
540 |
Message => $letter->{'is_html'} |
Lines 572-580
sub SendAlerts {
Link Here
|
572 |
) or return; |
586 |
) or return; |
573 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
587 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
574 |
my $email = Koha::Email->new(); |
588 |
my $email = Koha::Email->new(); |
|
|
589 |
my $emailaddr = $externalid->{'emailaddr'}; |
590 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
591 |
$emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
575 |
my %mail = $email->create_message_headers( |
592 |
my %mail = $email->create_message_headers( |
576 |
{ |
593 |
{ |
577 |
to => $externalid->{'emailaddr'}, |
594 |
to => $emailaddr, |
578 |
from => $library->{branchemail}, |
595 |
from => $library->{branchemail}, |
579 |
replyto => $library->{branchreplyto}, |
596 |
replyto => $library->{branchreplyto}, |
580 |
sender => $library->{branchreturnpath}, |
597 |
sender => $library->{branchreturnpath}, |
Lines 1223-1237
sub _send_message_by_email {
Link Here
|
1223 |
|
1240 |
|
1224 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1241 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1225 |
my $to_address = $message->{'to_address'}; |
1242 |
my $to_address = $message->{'to_address'}; |
|
|
1243 |
if (!$to_address && $member) { |
1244 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1245 |
} |
1246 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1247 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
1226 |
unless ($to_address) { |
1248 |
unless ($to_address) { |
1227 |
unless ($member) { |
1249 |
if (!$member) { |
1228 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1250 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1229 |
_set_message_status( { message_id => $message->{'message_id'}, |
1251 |
_set_message_status( { message_id => $message->{'message_id'}, |
1230 |
status => 'failed' } ); |
1252 |
status => 'failed' } ); |
1231 |
return; |
1253 |
return; |
1232 |
} |
1254 |
} |
1233 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1255 |
else { |
1234 |
unless ($to_address) { |
|
|
1235 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1256 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1236 |
# warning too verbose for this more common case? |
1257 |
# warning too verbose for this more common case? |
1237 |
_set_message_status( { message_id => $message->{'message_id'}, |
1258 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1276-1283
sub _send_message_by_email {
Link Here
|
1276 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
1297 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
1277 |
|
1298 |
|
1278 |
if ( sendmail( %sendmail_params ) ) { |
1299 |
if ( sendmail( %sendmail_params ) ) { |
1279 |
_set_message_status( { message_id => $message->{'message_id'}, |
1300 |
_set_message_status( { message_id => $message->{'message_id'}, |
1280 |
status => 'sent' } ); |
1301 |
status => 'sent' } ); |
1281 |
return 1; |
1302 |
return 1; |
1282 |
} else { |
1303 |
} else { |
1283 |
_set_message_status( { message_id => $message->{'message_id'}, |
1304 |
_set_message_status( { message_id => $message->{'message_id'}, |