本文发表在 rolia.net 枫下论坛这个是我以前写的Perl script,很简陋,参考下罢了
缺点是要装MIME:Lite之类Perl CPAN Lib.
如果你机子上有Java, 用JavaMail 一样好,还不用装任何东西
#!/usr/local/bin/perl -w
#
#Scripts wrapper to send out Metrics XLS everyday
use strict;
use MIME::Lite;
use Net::SMTP;
use Getopt::Std;
sub Usage($) {
my $program = shift;
print <<EOF;
This script will send a file by attach it as a MIME attachemnt
Usage: $program [-f from_address] [-s subject] -t to_address the_file_name_you_want_to_send
EOF
exit (1);
}
my $program = $0;
my $hostname = `/usr/bin/hostname`; chomp $hostname;
my $from_address = 'mimeSender@'.$hostname.'.telus.net';
my $to_address ;
my $subject;
my $mime_type = 'TEXT';
my $message = "This is a message sent from $hostname by mime message\
sender,\npls check attachment.\n";
my @timebit = localtime();
$subject = ($timebit[5]+1900) . "-" . ($timebit[4]+1) . "-" . $timebit[3];
$subject = "File sent on $subject";
my %opts;
getopts('f:s:t:', \%opts) || Usage($program);
if (!defined $opts{t}) {Usage($program); exit(1);}
$to_address = $opts{t};
$subject = $opts{s} if defined $opts{s};
# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
From => $from_address,
To => $to_address,
Subject => $subject,
Type => $mime_type,
Data => $message
)
or die "Error creating MIME body: $!\n";
#Get the program's running path
my $PathToProgram;
$0 =~ m!^(.*/)!;
$PathToProgram = $1;
#my $filename = shift || ($PathToProgram . "report.txt.gz");
my $filename = shift;
if (!defined $filename) { Usage($program); exit(1); }
my $recommended_filename = `/usr/bin/basename $filename`;
chomp $recommended_filename;
# Attach the test file
$mime_msg->attach(
Type => 'application/zip',
Path => $filename,
Filename => $recommended_filename
)
or die "Error attaching test file: $!\n";
my $message_body = $mime_msg->body_as_string();
$mime_msg->send();
## END更多精彩文章及讨论,请光临枫下论坛 rolia.net
缺点是要装MIME:Lite之类Perl CPAN Lib.
如果你机子上有Java, 用JavaMail 一样好,还不用装任何东西
#!/usr/local/bin/perl -w
#
#Scripts wrapper to send out Metrics XLS everyday
use strict;
use MIME::Lite;
use Net::SMTP;
use Getopt::Std;
sub Usage($) {
my $program = shift;
print <<EOF;
This script will send a file by attach it as a MIME attachemnt
Usage: $program [-f from_address] [-s subject] -t to_address the_file_name_you_want_to_send
EOF
exit (1);
}
my $program = $0;
my $hostname = `/usr/bin/hostname`; chomp $hostname;
my $from_address = 'mimeSender@'.$hostname.'.telus.net';
my $to_address ;
my $subject;
my $mime_type = 'TEXT';
my $message = "This is a message sent from $hostname by mime message\
sender,\npls check attachment.\n";
my @timebit = localtime();
$subject = ($timebit[5]+1900) . "-" . ($timebit[4]+1) . "-" . $timebit[3];
$subject = "File sent on $subject";
my %opts;
getopts('f:s:t:', \%opts) || Usage($program);
if (!defined $opts{t}) {Usage($program); exit(1);}
$to_address = $opts{t};
$subject = $opts{s} if defined $opts{s};
# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
From => $from_address,
To => $to_address,
Subject => $subject,
Type => $mime_type,
Data => $message
)
or die "Error creating MIME body: $!\n";
#Get the program's running path
my $PathToProgram;
$0 =~ m!^(.*/)!;
$PathToProgram = $1;
#my $filename = shift || ($PathToProgram . "report.txt.gz");
my $filename = shift;
if (!defined $filename) { Usage($program); exit(1); }
my $recommended_filename = `/usr/bin/basename $filename`;
chomp $recommended_filename;
# Attach the test file
$mime_msg->attach(
Type => 'application/zip',
Path => $filename,
Filename => $recommended_filename
)
or die "Error attaching test file: $!\n";
my $message_body = $mime_msg->body_as_string();
$mime_msg->send();
## END更多精彩文章及讨论,请光临枫下论坛 rolia.net