#!/usr/bin/env perl # This script tests the Mail::Sendmail mailing service which is used internally # by Koha. The script sends a test email to one or more recipients and displays # the result of the test. # Copyright 2010 Rick Welykochy, NSW, Australia # # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # Koha is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA use strict; use warnings; use Mail::Sendmail qw(sendmail %mailcfg); use Getopt::Long; use Sys::Hostname; sub help { print < \$help, 'verbose|v' => sub { $mailcfg{debug} = 6; $verbose = 1; }, 'nomail|n' => \$nomail ); if (!GetOptions(%options)) { print STDERR "$0: unrecognised command line argument. Try --help for help\n"; exit 1; } return help if $help; my @recipients = @ARGV; if (!@recipients) { print STDERR "$0: missing email recipient. Try --help for help\n"; exit 1; } my $from = "postmaster\@".hostname my $to = $recipients[0]; my $cc = @recipients > 1 ? join(", ",@recipients[1..@recipients-1]) : undef; my $subject = "Test email"; my $message = "Hello. This is a test email, sent by the Koha script $0.\n"; my %mail = ( To => $to, From => $from, Subject => $subject, Message => $message, 'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION", ); $mail{Cc} = $cc if $cc; dump_mail(%mail) if $nomail || $verbose; if ($nomail) { print "\nEmail not sent (--nomail)\n"; } else { $return = sendmail(%mail); print "Email log: $Mail::Sendmail::log\n" if $Mail::Sendmail::log && $verbose; print "Email error: $Mail::Sendmail::error\n" if $Mail::Sendmail::error; print "Email sent to @recipients.\n" if $return == 1; } return $return; } exit main;