#!/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 ); #### 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-- #### Content-Disposition: attachment; filename=blah.pl Content-Type: text/x-perl; name=blah.pl; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit #### $entity->attach( Disposition => 'attachment', Filename => "report.txt", Type => 'text/plain', Data => join( "\n", @attach ) ) or die "Error adding the text message part: $!\n"; #### Content-Type: text/plain; name="report.txt" Content-Disposition: attachment; filename="report.txt" Content-Transfer-Encoding: binary