in reply to mime tools attachments

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.