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 |
|
---|
34 | BEGIN {
|
---|
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 |
|
---|
40 | use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
|
---|
41 | use Mail::Sendmail;
|
---|
42 | use parsargv;
|
---|
43 |
|
---|
44 | if (!parsargv::parse(\@ARGV,
|
---|
45 | 'to/@', \$to,
|
---|
46 | 'from/@', \$from,
|
---|
47 | 'subject/.*/', \$subject,
|
---|
48 | 'smtp/.*', \$smtp,
|
---|
49 | 'msgfile/.*/', \$msgfile)) {
|
---|
50 | print STDERR "\n";
|
---|
51 | print STDERR "sendmail.pl: A simple platform independant mail sending program.\n\n";
|
---|
52 | print STDERR " usage: $0 [options]\n\n";
|
---|
53 | print STDERR " options:\n";
|
---|
54 | print STDERR " -to addr Comma separated list of mail recipients\n";
|
---|
55 | print STDERR " -from addr Address of message sender\n";
|
---|
56 | print STDERR " -subject str Optional subject line\n";
|
---|
57 | print STDERR " -smtp server The outgoing (SMTP) mail server\n";
|
---|
58 | print STDERR " -msgfile file A file from which message to be sent is read.\n";
|
---|
59 | print STDERR " If not set message will be read in from STDIN\n";
|
---|
60 | die "\n";
|
---|
61 | }
|
---|
62 |
|
---|
63 | my %mail = ('SMTP' => $smtp,
|
---|
64 | 'To' => $to,
|
---|
65 | 'From' => $from,
|
---|
66 | 'Subject' => $subject,
|
---|
67 | );
|
---|
68 |
|
---|
69 | my $msg = "";
|
---|
70 | if ($msgfile ne "") {
|
---|
71 | if (!open (MSGFILE, $msgfile)) {
|
---|
72 | print STDERR "ERROR: Failed to open $msgfile. Message was not sent\n";
|
---|
73 | exit (-1);
|
---|
74 | }
|
---|
75 | undef $/;
|
---|
76 | $msg = <MSGFILE>;
|
---|
77 | $/ = "\n";
|
---|
78 | close MSGFILE;
|
---|
79 | } else {
|
---|
80 | $msg = <STDIN>;
|
---|
81 | }
|
---|
82 |
|
---|
83 | $mail{'Message'} = $msg;
|
---|
84 |
|
---|
85 | if (!sendmail %mail) {
|
---|
86 | print STDERR "ERROR: Failed to send message\n";
|
---|
87 | print STDERR "'$Mail::Sendmail::error'\n";
|
---|
88 | exit (-1);
|
---|
89 | }
|
---|