Solved

adding mail attachment to script

Posted on 2007-12-06
4
470 Views
Last Modified: 2008-04-25
hi there
right now we cant send an attachment can anyone please modify it
thanks

#!D:\Perl\bin  -w


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

# my $server = 'mail.aa.com';
my $server = 'exchange.aa.com:25';
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";
      exit;
}


$mail{From} = 'Nexus Intel Server <+DW_team@aa.com>';
$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";
      }
}
else
{
    print "\n!Error sending mail:\n$Mail::Sendmail::error\n";
}
0
Comment
Question by:nav29
4 Comments
 
LVL 2

Expert Comment

by:zby
ID: 20426948
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 20435748
0
 

Author Comment

by:nav29
ID: 20435761
frnds
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
thanks
0
 
LVL 1

Accepted Solution

by:
r_jony earned 500 total points
ID: 20451970
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\@xyz.com");

    defined(${$header}{'To'}) || (${$header}{'To'} = "cd\@xyz.com");

    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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
I need a bash script converted to perl 9 219
HTTP Error 502.2 - Bad Gateway 3 197
perl split by | 2 81
Perl script to delete older files 6 45
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now