Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: MIME::Lite behaving strange

by bar10der (Beadle)
on Apr 01, 2009 at 15:18 UTC ( #754736=note: print w/replies, xml ) Need Help??


in reply to Re: MIME::Lite behaving strange
in thread MIME::Lite behaving strange

I have changed the code and this is how it looks now-
#!/usr/bin/perl -w use MIME::Lite; use strict; use warnings; my $mail_host = 'servername.com'; my $to='fname.lname@sun.com'; my $from="west"; my $subject="Reports"; my $body = "See attached reports.\n"; ### Create the multipart container my $msg = MIME::Lite->new ( From => $from, To => $to, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $body ) or die "Error adding the text message part: $!\n"; ### Add the file $msg->attach ( Type => 'text/plain; charset=UTF-8', Path => '/dir/dir/dir/report', Filename => 'test.txt', Disposition => 'attachment' ) or die "Error adding untouched_tickets.csv: $!\n"; ### Send the Message MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send;

Content of the test.txt on server is -

this is a test message

However content of the test.txt which came through email is -

mkStats.pl CheckDB.pl CleanUp.pl reports.pl
So the attachment is containing these 4 file names everytime I send email, no matter which file I am attaching.

Replies are listed 'Best First'.
Re^3: MIME::Lite behaving strange
by jethro (Monsignor) on Apr 01, 2009 at 15:38 UTC

    You set 'Filename' to test.txt, but Filename is only how the file is called in the attachment. The file itself should be found in 'Path'. So Path     => '/path/to/the/file/test.txt' (or Path => 'test.txt' if the file is in the current path) would be more appropriate to get anything useful (with appropriate values for /path/to/the/file)

      Ah...that was it then!! Many thanks for helping me out. Really appreciate your help.
      it is throwing me error : Failed to connect to mail server: Invalid Argument on this line: $msg->send; where the arguments passed are same as shown above
        it is throwing me error : Failed to connect to mail server: Invalid Argument on this line: $msg->send; where the arguments passed are same as shown above

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://754736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2021-10-22 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?