in reply to Re: Error in MIME::Lite?
in thread Error in MIME::Lite?

I called build() twice for clarity. The test case fails with a single build() call.
$msg->build(to => 'user1 <user@fqdn.org>', from => 'user2 <user2@fqdn. +org>', subject => 'a message subject'); % ./testmail.pp no data in this part at ./testmail.pp line 21.
The problem is that the MIME::Lite->attach() creates a new part with no content unless the content-type is already set to multipart. This is not legal as far as MIME::Lite->send() is concerned.

I tried setting content-type but that breaks the MIME formatting of the message (all the steps that attach() is doing unless it detects multipart).

Replies are listed 'Best First'.
Re^3: Error in MIME::Lite?
by Anonymous Monk on Jul 29, 2017 at 20:36 UTC

    Hi

    I think build wants data also

      The poorly documented answer is that new() requires data. I was able to get it to work, but only when I either pass new() data (text, html or an attachment) or reproduce the logic in attach() to create a multi-part mime format. You can't create a new empty object and add data to it.

        You can't create a new empty object and add data to it.

        Sure you can

        #!/usr/bin/perl -- use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new; ## no data $msg->build( qw/ to you from me Data Data1 /); ## data $msg->build( qw/ subject SUBJECT /)->data('Data2'); ## data $msg->attach( qw/ Data DATA3 /); ## data $msg->print; __END__ Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_150136405630120" MIME-Version: 1.0 Date: Sat, 29 Jul 2017 14:34:16 -0700 To: you From: me Date: Sat, 29 Jul 2017 14:34:16 -0700 Subject: SUBJECT X-Mailer: MIME::Lite 3.029 (F2.84; T2.04; A2.12; B3.14; Q3.13) This is a multi-part message in MIME format. --_----------=_150136405630120 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain Data2 --_----------=_150136405630120 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain DATA3 --_----------=_150136405630120--