in reply to Error in MIME::Lite?
Notice that MIME::Lite::attach() created 2 parts, one (part0) master with no data and part1 with the text data, but send() barfs on this. Is this a bug in the module or am I doing something wrong?
Not a bug. If you create a message, there should be data in it, even if it is no data:
qwurx [shmem] ~> perl -MMIME::Lite -le '$m=MIME::Lite->new(Data=>"foo" +);$m->print' Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.030 (F2.85; T2.09; A2.13; B3.14; Q3.13) Date: Sun, 30 Jul 2017 02:30:09 +0200 foo
Also:
qwurx [shmem] ~> perl -MMIME::Lite -le '$m=MIME::Lite->new;$m->build(f +rom => "me", to =>"you", Data => "kisses"); $m->print' Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.030 (F2.85; T2.09; A2.13; B3.14; Q3.13) Date: Sun, 30 Jul 2017 02:32:39 +0200 From: me To: you kisses
These are just plain messages. You can also build a message with no data using Data => "" in the constructor or build(). MIME::Lite builds a multipart message only if there are, well, multiple parts.
use MIME::Lite; $m = MIME::Lite->new; $m->build( from => 'me', to => 'you', Data => '', subject => 'Foo Bar', ); $m->attach( Type => 'text/plain', Data => 'this is an attachment' ); $m->print; __END__ Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_150137533476690" MIME-Version: 1.0 Date: Sun, 30 Jul 2017 02:42:14 +0200 From: me To: you Subject: Foo Bar X-Mailer: MIME::Lite 3.030 (F2.85; T2.09; A2.13; B3.14; Q3.13) This is a multi-part message in MIME format. --_----------=_150137533476690 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain --_----------=_150137533476690 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain this is an attachment --_----------=_150137533476690--
What you have gotten wrong is this part in your code
$msg->attach( Type => 'text/plain', Data => 'This is the body text of the email', );
It isn't the body text of the mail. It is an attachment. The body part is the first part of the multipart message, and you must provide data for it (even an empty string works) either in the constructor, or the build or the data method invoked upon the MIME::Lite object.
|
|---|