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

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.

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

    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--
      Aha! There's the issue:
      % diff foo.pl bar.pl 7c7 < $msg->build(subject => 'a message subject')->data('Data2'); --- > $msg->build(subject => 'a message subject'); foo.pl -> 0 bar.pl -> 1
      Why is the ->data() required?

        Because its written that way?

        build returns an object of some kind ... if you dont specify data in constructor, you have to specify it later ...

        Notice also data1 is disappeared :)