adding mail attachment to script

hi there
right now we cant send an attachment can anyone please modify it

#!D:\Perl\bin  -w

# if you change your mail server, you may need to change the From:
# address below.

# my $server = '';
my $server = '';
my $this_machine = 'sottnex24';
my ($to, $subject, $file_path, $file, $body);

use Mail::Sendmail;

if ($server) {
    $mail{Smtp} = $server;

# parse parameters

if ( @ARGV == 3 )
      ($to, $subject, $body) = @ARGV;
elsif ( @ARGV == 5 )
      ($to, $subject, $file_path, $file, $body) = @ARGV;
elsif (@ARGV < 3)
      print "Usage: to | subject [file_path | file ] | body\n";

$mail{From} = 'Nexus Intel Server <>';
$mail{To}   = $to;
$mail{Subject} = $subject;
$mail{Message} .= "$body \n
Sent from $this_machine \n
At: " . Mail::Sendmail::time_to_date() . "\n";

# Go send it

if (sendmail %mail) {
    # print "content of \$Mail::Sendmail::log:\n$Mail::Sendmail::log\n";
    if ($Mail::Sendmail::error)
       print "content of \$Mail::Sendmail::error:\n$Mail::Sendmail::error\n";
    print "\n!Error sending mail:\n$Mail::Sendmail::error\n";
Who is Participating?
This is the code snippet that you would like to use in your script, using your own variables

use MIME::Lite;
#This indicates that we want to use smtp
MIME::Lite->send('smtp', $ipaddress, Timeout=>60, Port=>2525) or abort "failed"; 
send_mime_message($username,{Subject => 'hello there', Type => 'application/octet-stream', Path =>"/tmp/binary.$$", Disposition => 'attachment'});
#Subroutines to send the messages with the attachment
sub send_mime_message
    my $username=shift;
    #The parts to construct, anonymous arrays of anonymous hash. parts[0] always contain header info,
    #plus mail data if not sending multipart mail
    my $parts = [@_];
    my $header = ${$parts}[0];
    defined(${$header}{'From'}) || (${$header}{'From'} = "abc\");
    defined(${$header}{'To'}) || (${$header}{'To'} = "cd\");
    defined(${$header}{'Subject'}) || (${$header}{'Subject'} = "message here");
    my $msg = MIME::Lite->new( %{$header});
    abort "no object " if !defined($msg);
    $msg->send() || fail "Couldn't send message!";

Open in new window

nav29Author Commented:
i am not good at perl at all
this perl script was written by sumone it do send mail not mail attachment
if u guys have a sec can u please attach tht code to the script above to send attachment with mail
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.