[Koha-patches] [PATCH] Enhancement: [3.2] (Resubmission) Adding code to support using gmail as an SMTP server
Chris Nighswonger
cnighswonger at foundations.edu
Fri Feb 19 14:21:02 CET 2010
This patch adds support for using a gmail account as an SMTP server.
It includes a basic HOWTO.
---
C4/Letters.pm | 4 +-
misc/cronjobs/CONFIGURE.gmail | 65 ++++++++++++++++++++++++++++++++
misc/cronjobs/process_message_queue.pl | 22 ++++++++---
3 files changed, 84 insertions(+), 7 deletions(-)
create mode 100644 misc/cronjobs/CONFIGURE.gmail
diff --git a/C4/Letters.pm b/C4/Letters.pm
index fb8de54..cfc3665 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -618,7 +618,7 @@ sub SendQueuedMessages (;$) {
# This is just begging for subclassing
next MESSAGE if ( lc($message->{'message_transport_type'}) eq 'rss' );
if ( lc( $message->{'message_transport_type'} ) eq 'email' ) {
- _send_message_by_email( $message );
+ _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} );
}
elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
_send_message_by_sms( $message );
@@ -775,6 +775,7 @@ ENDSQL
sub _send_message_by_email ($;$$$) {
my $message = shift or return;
+ my ($username, $password, $method) = @_;
my $to_address = $message->{to_address};
unless ($to_address) {
@@ -803,6 +804,7 @@ sub _send_message_by_email ($;$$$) {
Message => $content,
'content-type' => $message->{'content_type'} || 'text/plain; charset="UTF-8"',
);
+ $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) {
$sendmail_params{ Bcc } = $bcc;
}
diff --git a/misc/cronjobs/CONFIGURE.gmail b/misc/cronjobs/CONFIGURE.gmail
new file mode 100644
index 0000000..221c583
--- /dev/null
+++ b/misc/cronjobs/CONFIGURE.gmail
@@ -0,0 +1,65 @@
+=============================
+Installation Guide for Configuring a Koha Server to Use a Gmail Account as its SMTP Server
+=============================
+
+Copyright (C) 2010 Foundations Bible College (http://www.foundations.edu)
+
+Author: Chris Nighswonger (cnighswonger AT foundations DOT edu
+
+Feedback/bug reports: Koha Developer's List:
+http://lists.koha.org/mailman/listinfo/koha-devel
+
+This document last modified: 13 February 2010
+
+Configuration Instructions
+=============================
+
+To use your gmail account as an SMTP server you will need to execute the following from a shell prompt.
+
+(These steps are taken from http://jonspriggs.posterous.com/use-gmails-smtp-gateway-using-the-command-lin)
+
+sudo apt-get install openssl xinetd
+
+sudo tee /usr/bin/gmail-smtp <<EOF >/dev/null
+#!/bin/sh
+# Thanks to http://ubuntuforums.org/showthread.php?t=918335 for this install guide
+/usr/bin/openssl s_client -connect smtp.gmail.com:465 -quiet 2>/dev/null
+EOF
+sudo chmod +x /usr/bin/gmail-smtp
+
+sudo tee /etc/xinetd.d/gmail-smtp <<EOF >/dev/null
+# default: on
+# description: Gmail SMTP wrapper for clients without SSL support
+# Thanks to http://ubuntuforums.org/showthread.php?t=918335 for this install guide
+service gmail-smtp
+{
+ disable = no
+ bind = localhost
+ port = 10025
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = root
+ server = /usr/bin/gmail-smtp
+ type = unlisted
+}
+EOF
+sudo /etc/init.d/xinetd reload
+
+Edit Mail/Sendmail.pm and set the port to 10025. (Note: This file will be located where ever your Perl libraries are.)
+
+Script Setup Instructions
+=============================
+
+After successfully executing the above steps, you will need to run the process_message_queue.pl script with the
+following syntax:
+
+perl process_message_queue.pl -u librarian at foo.tld -p supersecret -m LOGIN
+
+This, of course, assumes that you have all other scripts in place and functional to generate notices.
+
+Misc Helpful Notes
+=============================
+
+NOTE: In order to debug problems, you can set the debug level in Mail/Sendmail.pm to 11 which will give plenty of
+commentary to STDOUT.
diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl
index af9b1b3..3ff956e 100755
--- a/misc/cronjobs/process_message_queue.pl
+++ b/misc/cronjobs/process_message_queue.pl
@@ -28,12 +28,19 @@ BEGIN {
use C4::Letters;
use Getopt::Long;
+my $username = undef;
+my $password = undef;
+my $method = 'LOGIN';
my $help = 0;
my $verbose = 0;
-GetOptions( 'h' => \$help,
- 'v' => \$verbose,
- );
+GetOptions(
+ 'u|username:s' => \$username,
+ 'p|password:s' => \$password,
+ 'm|method:s' => \$method,
+ 'h|help|?' => \$help,
+ 'v|verbose' => \$verbose,
+);
my $usage = << 'ENDUSAGE';
This script processes the message queue in the message_queue database
@@ -43,12 +50,15 @@ you run this regularly from cron, especially if you are using the
advance_notices.pl script.
This script has the following parameters :
- -h help: this message
- -v verbose
+ -u --username: username of mail account
+ -p --password: password of mail account
+ -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
+ -h --help: this message
+ -v --verbose: provides verbose output to STDOUT
ENDUSAGE
die $usage if $help;
-C4::Letters::SendQueuedMessages( { verbose => $verbose } );
+C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } );
--
1.6.0.4
More information about the Koha-patches
mailing list