source: trunk/gsdl/bin/script/sendmail.pl@ 1777

Last change on this file since 1777 was 1777, checked in by sjboddie, 23 years ago

Created sendmail.pl - a wrapper around the Sendmail perl module for use
as a platform independant sendmail program.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# sendmail.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2000 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28# sendmail.pl is a simple wrapper around the Sendmail perl module written
29# by Milivoj Ivkovic <[email protected]>
30
31# Input is either read from STDIN or, if the -msgfile option is set, read
32# from the given file.
33
34BEGIN {
35 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
36 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
38}
39
40use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
41use Mail::Sendmail;
42use parsargv;
43
44if (!parsargv::parse(\@ARGV,
45 'to/@', \$to,
46 'from/@', \$from,
47 'subject/.*/', \$subject,
48 'smtp/.*', \$smtp,
49 'msgfile/.*/', \$msgfile)) {
50 print STDERR "\n usage: $0 [options]\n\n";
51 print STDERR " options:\n";
52 print STDERR " -to addr Comma separated list of mail recipients\n";
53 print STDERR " -from addr Address of message sender\n";
54 print STDERR " -subject str Optional subject line\n";
55 print STDERR " -smtp server The outgoing (SMTP) mail server\n";
56 print STDERR " -msgfile file A file from which message to be sent is read.\n";
57 print STDERR " If not set message will be read in from STDIN\n";
58 die "\n";
59}
60
61my %mail = ('SMTP' => $smtp,
62 'To' => $to,
63 'From' => $from,
64 'Subject' => $subject,
65 );
66
67my $msg = "";
68if ($msgfile ne "") {
69 if (!open (MSGFILE, $msgfile)) {
70 print STDERR "ERROR: Failed to open $msgfile. Message was not sent\n";
71 exit (-1);
72 }
73 undef $/;
74 $msg = <MSGFILE>;
75 $/ = "\n";
76 close MSGFILE;
77} else {
78 $msg = <STDIN>;
79}
80
81$mail{'Message'} = $msg;
82
83if (!sendmail %mail) {
84 print STDERR "ERROR: Failed to send message\n";
85 print STDERR "'$Mail::Sendmail::error'\n";
86 exit (-1);
87}
Note: See TracBrowser for help on using the repository browser.