Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Extra lines after boundary (MIME::Lite + mod_perl)

by Ricardo Urbina (Initiate)
on Apr 05, 2013 at 21:25 UTC ( #1027223=perlquestion: print w/replies, xml ) Need Help??
Ricardo Urbina has asked for the wisdom of the Perl Monks concerning the following question:

I'm sending a mutlipart email with a couple of attachments. In a pinch, this is the code:

my $mime = MIME::Lite->new( From => 'admin@server', To => 'you@overthere', Subject => "Your invoice", Type => 'multipart/mixed', ); $mime->attach( Data => 'Heres your invoice' ); $mime->attach( Data => $invoice_as_pdf, Type => 'AUTO', Dispositio +n => 'attachment', Filename => 'invoice.pdf' ); $mime->send( 'sendmail', FromSender => 'admin@server' );

If you just run it, it works. But when it's called from our app running in mod_perl, it gets an extra \n after the boundary, which means MUA won't parse the headers, you don't really get an option to download the file, it's a wreck, looks like this:

MIME-Version: 1.0 Content-Transfer-Encoding: binary Content-Type: multipart/mixed; boundary="_----------=_1365192382184080 +" X-Mailer: MIME::Lite 3.028 (F2.82; T1.34; A2.09; B3.13; Q3.13) Date: Fri, 5 Apr 2013 14:06:22 -0600 From: admin@server To: you@overthere Subject: Your invoice This is a multi-part message in MIME format. --_----------=_1365192382184080 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain Heres your invoice --_----------=_1365192382184080 Content-Disposition: attachment; filename="invoice.pdf" Content-Transfer-Encoding: base64 Content-Type: application/octet-stream; name="invoice.pdf" JVBERi0xLjQKMSAwIG9iago8PAovVGl0bGUgKP7/AEEAbABnA....== --_----------=_1365192382184080--

Of course the MUA displays the Content-* lines and the base64 file.

So far I found that MIME::Lite opens a pipe to sendmail, prints the boundary to the handle and then passes the handle to a function which prints the part to it. As a matter of fact, I opened and used the $part->to_string method to print it along with the boundary in a single call and it worked just fine.

My best guess is that someone/something is messing with the stream, but I have no clue. Anyone ever observed a problem like this one before? Any clues? Any MIME::Lite alternatives which would work with my sample code? I need it to use sendmail and be able to force the From field because I'm using Amazon's relay servers.

Replies are listed 'Best First'.
Re: Extra lines after boundary (MIME::Lite + mod_perl)
by Anonymous Monk on Apr 06, 2013 at 07:29 UTC

    an extra \n after the boundary

    After what?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027223]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-09-22 09:05 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (260 votes). Check out past polls.