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 MIME::Lite.pm 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.


In reply to Extra lines after boundary (MIME::Lite + mod_perl) by Ricardo Urbina

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.