in reply to Send an email attachment
Take a look at Email::Stuffer
#!/usr/bin/perl use strict; use warnings; use Sys::Hostname; use Email::Sender::Transport::SMTP; use Email::Stuffer; my $from = '***@****.com'; my $to = '***@****.com'; my $cc; if ($ARGV[-1] eq '-t'){ pop @ARGV; $cc = '****@*****.com'; } if (@ARGV < 1 or @ARGV > 2){ usage(); exit; } my $host = hostname(); my $logfile = $ARGV[0]; die "$logfile does not exists " unless (-e $logfile); my $subject = $ARGV[1] || "$host: $logfile"; my $msg = Email::Stuffer->new({ from => $from, to => $to, subject => $subject, text_body=> "Here is attachment"}); $msg->cc($cc) if $cc; $msg->attach_file($logfile); #print $msg->as_string; my $transport_obj = Email::Sender::Transport::SMTP->new({ host => '****', debug => 1, }); $msg->transport( $transport_obj ); $msg->send_or_die; sub usage { print << "EOF"; usage : mailsend.pl <logfile> [subject] [-t] syntax : logfile is required. [subject] is optional. [-t] specifies to send a copy to maileater print "example: mailsend.pl /tmp/test.log print "example: mailsend.pl /tmp/test.log Test print "example: mailsend.pl /tmp/test.log Test -t EOF }
|
|---|