ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/Mailer.pm
Revision: 24
Committed: Tue Jul 26 21:46:39 2011 UTC (8 years, 1 month ago) by gpertea
File size: 1968 byte(s)
Log Message:
Line File contents
1 #!/usr/bin/perl
2 use strict 'vars';
3 #use Mail::Mailer;
4 use POSIX 'uname';
5 use IO::File;
6
7 #------- retrieve the local host name
8
9 my $thisHost= (&POSIX::uname)[1]; # can't trust HOST envvar under condor, because for getenv=TRUE
10 # it will either inherit HOST and HOSTNAME from submitter env
11 # or not set anything for getenv=FALSE
12 # --> so we use POSIX uname() call here
13 chomp($thisHost);
14 $thisHost=lc($thisHost);
15 my ($thisDomain)=($thisHost=~/^[\w\-]+\.(.+)/);
16
17 #my $def_domain = 'jimmy.harvard.edu';
18 my $def_domain = $thisDomain;
19 $def_domain=~s/^dfci\./jimmy\./;
20 my $def_host = $thisHost;
21
22 #----------------------
23 sub send_mail {
24 my $hash=shift;
25 $hash->{'from'}=$ENV{'USER'}.'@'.$def_host
26 unless defined($hash->{'from'});
27 my $to=$hash->{'to'};
28 unless ($to) {
29 $hash->{'to'}=$ENV{'USER'}.'@'.$def_domain;
30 }
31 else {
32 $hash->{'to'}=$to.'@'.$def_domain unless $to =~ m/@/;
33 }
34
35 my $file;
36 local *ADDFILE;
37 if (defined($hash->{file})) {
38 #warning: assumes it's a decent, short text file!
39 local $/=undef; #read whole file
40 open(ADDFILE, '<'.$hash->{file}) || return "Cannot open file ".$hash->{file}."\n";
41 $file=<ADDFILE>;
42 close ADDFILE;
43 }
44 my $body = $hash->{'body'};
45 $body.=$file;
46 my $fh;
47 $fh = IO::File->new('| /usr/lib/sendmail -t -oi') ||
48 die("Mailer.pm error: Cannot open the sendmail pipe\n");
49 $fh->print("To: $hash->{to}\n");
50 $fh->print("From: $hash->{from}\n");
51 $fh->print("Subject: $hash->{subj}\n\n");
52 $fh->print($body);
53 $fh->close();
54
55 #-- create the Mail::Mailer object and send the message:
56 # my $mailer = Mail::Mailer->new();
57 # $mailer->open({ 'From' => $hash->{'from'},
58 # 'To' => $hash->{'to'},
59 # 'Cc' => $hash->{'cc'},
60 # 'Subject' => $hash->{'subj'}
61 # })
62 # or die "Mailer.pm error: Can't open. $!\n";
63 #print $mailer $body;
64 #$mailer->close();
65 }

Properties

Name Value
svn:executable *