ebodine has asked for the wisdom of the Perl Monks concerning the following question:

Allow me to preface my question w/ the statement that I am NOT a spammer. I am attempting to test a product that increases/extends Exchange 2000's functionality and stability (please hold snickering to a minimum ;-)

In order to do this I am using MIME::Lite to create/send lots of email w/ attachments (1-10MB in size) in order to fill up mailboxes w/ data and test the product's data restore functionality. The MIME conversion is rather expensive in terms of CPU time and I would like to cut this time down as well as use 5.8 threads (3 or 4) to send more email. Is there anyway to pre-MIME a file?? Is there a better way to do this, ie. 'CDONTS.Newmail' or Mail::Sender?

--ERick

Replies are listed 'Best First'.
Re: 'pre-MIMEing' an attachment?
by Anonymous Monk on Jan 24, 2003 at 22:53 UTC
    I read the MIME RFC for a little something I'm working
    on ( I should really start working on it again :-).
    I think this really cheap code will help you:
    use MIME::Base64; $smtp->data(); $smtp->datasend( "\nSubject: $subj \nMIME-Version: 1.0" ); $smtp->datasend( "\nContent-Type: multipart/mixed;boundary=\"Bb0uNddAr +ray\"" ); $smtp->datasend( "\n--Bb0uNddArray" ); $smtp->datasend( "\nContent-type: text/plain" ); $smtp->datasend( "\n\n$msg\n\n" ); # plaintext body if( $attachement ) { $smtp->datasend( "--Bb0uNddArray" ); $smtp->datasend( "\nContent-Type: $content_type; name=\"$filename\" +" ); $smtp->datasend( "\nContent-Transfer-Encoding: base64\n\n" ); while ( read( $file, $buff, 512 ) { $smtp->datasend( encode_base64($buff) ) || die"cant encode: $!"; } } # if attachement $smtp->datasend( "\n\n--Bb0uNddArray--" ); # send this even if ther +es no attachment $smtp->dataend(); $smtp->quit;
    This is untested,
    $smtp is a Net::SMTP handle

    Hope it helps
    -bl0rf

Re: 'pre-MIMEing' an attachment?
by tachyon (Chancellor) on Jan 25, 2003 at 01:47 UTC

    If you use Data::Dumper on your MIME::Lite object you will see that it is just the text string of the MIME formatted email.

    So all you need to do to send the same message to a large number of recipients is this:

    $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'recipient@yourhost.com', Subject =>'Helloooooo, nurse!', Type =>'image/gif', Encoding =>'base64', Path =>'hellonurse.gif' ); # add multipart(s) to $msg in the usual way for my $recipient (@recipients) { $msg =~ s/To: (.*)/To: $recipient/; $msg->send; }

    All we are doing is rewriting the To: foo@bar.com part of the header which has the desired effect. You could also just do a Cc like:

    my $cc = join ', ', @recipients; $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>$cc, Subject =>'Helloooooo, nurse!', Type =>'image/gif', Encoding =>'base64', Path =>'hellonurse.gif' ); $msg->send;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print