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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.