#!/usr/bin/perl -w # # Modified / updated by k2patel@gmail.com # This script send email with attachment #use strict; use MIME::Lite; use Getopt::Std; use Net::SMTP; my $SMTP_SERVER = '/usr/sbin/sendmail -t'; my $DEFAULT_SENDER = 'k2patel@localhost.localdomain'; my $DEFAULT_RECIPIENT = 'k2patel@hotmail.com'; my $def_cc = 'sjohn@live.com'; my $stamp = `date -d 'now -1 days' +%b-%d-%y`; my $hstnm = `hostname`; # process options getopts('hf:t:s:', \%o); $o{f} ||= $DEFAULT_SENDER; $o{t} ||= $DEFAULT_RECIPIENT; $o{s} ||= $stamp.' '.$hstnm.' '.' : System utilizatoin Report'; if ($o{h} or !@ARGV) { die "usage:\n\t$0 -h -f -t -s /var/log/log.txt\n"; } # construct and send email $msg = new MIME::Lite( From => $o{f}, To => $o{t}, cc => ($def_cc), Subject => $o{s}, Data => "Hi", Type => "multipart/mixed", ); while (@ARGV) { $msg->attach('Type' => 'application/octet-stream', 'Encoding' => 'base64', 'Path' => shift @ARGV); } $msg->send();