From a48839a6723db61119454d86e15dd930bf3489ff Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Fri, 19 Feb 2010 08:18:33 -0500 Subject: [PATCH] [SIGNED-OFF] Enhancement: [3.2] (Resubmission) Adding code to support using gmail as an SMTP server This patch adds support for using a gmail account as an SMTP server. It includes a basic HOWTO. Signed-off-by: Magnus Enger --- 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 34e3686..269ec78 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -624,7 +624,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 ); @@ -789,6 +789,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) { @@ -824,6 +825,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 </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 </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@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 4ff29a4..c79fea8 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.7.1