I'm not that familiar with mime-tools, but I'll take a stab at your problem, and hopefully I can help.

First of all, my testing code, and its output (mostly taken from what you posted).

Code:

#!/usr/bin/perl -w use strict; use MIME::Entity; my @attach = ( q{This is to inform you}, q{that you have won}, q{a number of tribbles.} ); my @msg_body = ( q{This is to inform you}, q{that this is}, q{a test.} ); my $entity = MIME::Entity->build( Type => 'multipart/mixed', From => 'email', To => 'address', Subject => "blah", ) or die "Error creating MIME entity: $!\n"; $entity->attach( Type => 'text/plain', #Encoding => 'base64', Data => join( "\n", @msg_body ) ); $entity->attach( Filename => "report.txt", Type => 'text/plain', Data => join( "\n", @attach ) ) or die "Error adding the text message part: $!\n"; # $entity->smtpsend; $entity->print( \*STDOUT );

Output:

Content-Type: multipart/mixed; boundary="----------=_1097554778-11801- +0" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.411 (Entity 5.404) From: email To: address Subject: blah This is a multi-part message in MIME format... ------------=_1097554778-11801-0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: binary This is to inform you that this is a test. ------------=_1097554778-11801-0 Content-Type: text/plain; name="report.txt" Content-Disposition: inline; filename="report.txt" Content-Transfer-Encoding: binary This is to inform you that you have won a number of tribbles. ------------=_1097554778-11801-0--

I then compared this with the source for an email in which I sent a coworker a perl script, in which the headers for that (which does show up as an attachment) are as follows:

Content-Disposition: attachment; filename=blah.pl Content-Type: text/x-perl; name=blah.pl; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit

I suspect strongly that the issue is that in the results of your code, the Content-Disposition is 'inline', rather than 'attachment', suggesting to the mail client to attempt to display it rather than show it as an attachment. So, in the code, I changed the attach line for 'report.txt' to the following, which seems to generate the appropriate entry:

$entity->attach( Disposition => 'attachment', Filename => "report.txt", Type => 'text/plain', Data => join( "\n", @attach ) ) or die "Error adding the text message part: $!\n";

Having done that, the headers for that section became:

Content-Type: text/plain; name="report.txt" Content-Disposition: attachment; filename="report.txt" Content-Transfer-Encoding: binary

I'm not sure that is quite the preferred way to do it, but it seems as if it might help. You would need to test to verify, however.

I hope that helps.


In reply to Re: mime tools attachments by atcroft
in thread mime tools attachments by Anonymous Monk

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.