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.

In reply to Re^2: MIME::Lite behaving strange by bar10der
in thread MIME::Lite behaving strange by bar10der

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.