source: main/trunk/greenstone2/bin/script/sendmail.pl@ 22642

Last change on this file since 22642 was 11844, checked in by mdewsnip, 18 years ago

Added an option to send the message as HTML.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 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 'html', \$html,
49 'smtp/.*', \$smtp,
50 'msgfile/.*/', \$msgfile)) {
51 print STDERR "\n";
52 print STDERR "sendmail.pl: A simple platform independant mail sending program.\n\n";
53 print STDERR " usage: $0 [options]\n\n";
54 print STDERR " options:\n";
55 print STDERR " -to addr Comma separated list of mail recipients\n";
56 print STDERR " -from addr Address of message sender\n";
57 print STDERR " -subject str Optional subject line\n";
58 print STDERR " -html Send message as HTML\n";
59 print STDERR " -smtp server The outgoing (SMTP) mail server\n";
60 print STDERR " -msgfile file A file from which message to be sent is read.\n";
61 print STDERR " If not set message will be read in from STDIN\n";
62 die "\n";
63}
64
65my %mail = ('SMTP' => $smtp,
66 'To' => $to,
67 'From' => $from,
68 'Subject' => $subject,
69 );
70
71my $msg = "";
72if ($msgfile ne "") {
73 if (!open (MSGFILE, $msgfile)) {
74 print STDERR "ERROR: Failed to open $msgfile. Message was not sent\n";
75 exit (-1);
76 }
77 undef $/;
78 $msg = <MSGFILE>;
79 $/ = "\n";
80 close MSGFILE;
81} else {
82 $msg = <STDIN>;
83}
84
85$mail{'Content-type'} = "text/html; charset=\"iso-8859-1\"" if ($html);
86$mail{'Message'} = $msg;
87
88if (!sendmail %mail) {
89 print STDERR "ERROR: Failed to send message\n";
90 print STDERR "'$Mail::Sendmail::error'\n";
91 exit (-1);
92}
Note: See TracBrowser for help on using the repository browser.