[Koha-patches] [PATCH] (bug #3540) create a sendemail function and use it
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Wed Aug 19 10:09:16 CEST 2009
This patch create new function C4::Letters::sendemail that permit to send e-mail and use a preference in koha-conf.xml to define the SMTP server to be used.
Then, all the places where Mail::Sendmail::sendmail was used, this replace, and use now C4::Letters::sendemail, and in cronjobs only the syspref was added.
---
C4/Letters.pm | 31 +++++++++++++++++++++++++------
C4/Suggestions.pm | 4 ++--
misc/cronjobs/runreport.pl | 1 +
misc/cronjobs/smsoverdues.pl | 3 ++-
4 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/C4/Letters.pm b/C4/Letters.pm
index b30b509..f691a21 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -37,7 +37,7 @@ BEGIN {
$VERSION = 3.01;
@ISA = qw(Exporter);
@EXPORT = qw(
- &GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts
+ &GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts &sendemail
);
}
@@ -283,7 +283,7 @@ sub SendAlerts {
Message => "" . $innerletter->{content},
'Content-Type' => 'text/plain; charset="utf8"',
);
- sendmail(%mail);
+ sendemail(%mail);
# warn "sending to $mail{To} From $mail{From} subj $mail{Subject} Mess $mail{Message}";
}
@@ -344,7 +344,7 @@ sub SendAlerts {
Message => "" . $innerletter->{content},
'Content-Type' => 'text/plain; charset="utf8"',
);
- sendmail(%mail);
+ sendemail(%mail);
warn
"sending to $mail{To} From $mail{From} subj $mail{Subject} Mess $mail{Message}";
}
@@ -414,7 +414,7 @@ sub SendAlerts {
Message => "" . $innerletter->{content},
'Content-Type' => 'text/plain; charset="utf8"',
);
- sendmail(%mail);
+ sendemail(%mail);
logaction(
"ACQUISITION",
"CLAIM ISSUE",
@@ -445,7 +445,7 @@ sub SendAlerts {
Message => $letter->{'content'},
'Content-Type' => 'text/plain; charset="utf8"',
);
- sendmail(%mail);
+ sendemail(%mail);
}
}
@@ -681,6 +681,25 @@ ENDSQL
return $sth->fetchall_arrayref({});
}
+=head2 sendemail
+
+This function must be used to send e-mail to users, it permit to have a
+central control point to manage differents configurations like the
+SMTP server to use.
+
+parameters:
+%email - the e-mail to send, this must be in the needed format for Mail::Sendmail
+
+returns the result of sendmail command
+
+=cut
+
+sub sendemail {
+ my (%email) = @_;
+ $email{smtp} = C4::Context->config('smtpserver') || 'localhost';
+ return sendmail(%email);
+}
+
=head2 _add_attachements
named parameters:
@@ -776,7 +795,7 @@ sub _send_message_by_email ($) {
$sendmail_params{'content-type'} = 'text/plain; charset="UTF-8"';
}
- my $success = sendmail( %sendmail_params );
+ my $success = sendemail( %sendmail_params );
if ( $success ) {
# warn "Sendmail OK. Log says: " . $Mail::Sendmail::log;
diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm
index c358d7a..9ae9178 100644
--- a/C4/Suggestions.pm
+++ b/C4/Suggestions.pm
@@ -20,11 +20,11 @@ package C4::Suggestions;
use strict;
use CGI;
-use Mail::Sendmail;
use C4::Context;
use C4::Output;
use C4::Dates qw(format_date);
+use C4::Letters qw(sendemail);
use vars qw($VERSION @ISA @EXPORT);
BEGIN {
@@ -433,7 +433,7 @@ sub ModStatus {
Message => "".$template->output,
'Content-Type' => 'text/plain; charset="utf8"',
);
- sendmail(%mail);
+ sendemail(%mail);
}
=head2 ConnectSuggestionAndBiblio
diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl
index b2e4af9..02daf46 100755
--- a/misc/cronjobs/runreport.pl
+++ b/misc/cronjobs/runreport.pl
@@ -180,6 +180,7 @@ foreach my $report (@ARGV) {
Subject => $subject,
Message => $message
);
+ $mail{smtp} = C4::Context->config('smtpserver') || 'localhost';
sendmail(%mail) or warn "mail not sent";
} else {
print $message;
diff --git a/misc/cronjobs/smsoverdues.pl b/misc/cronjobs/smsoverdues.pl
index a0b7da0..b409a26 100755
--- a/misc/cronjobs/smsoverdues.pl
+++ b/misc/cronjobs/smsoverdues.pl
@@ -306,7 +306,8 @@ sub sendEmail {
From => $from,
Subject => $subject,
Message => $message);
-
+
+ $mail{smtp} = C4::Context->config('smtpserver') || 'localhost';
if (not(sendmail %mail)) {
warn $Mail::Sendmail::error;
--
1.6.0.4
More information about the Koha-patches
mailing list