Hello monks, Im trying to send an email which has both html and plaintext in the body. I'm using MIME::entity and Mail::Mailer. Simplified code:
use MIME::Entity; use Mail::Mailer qw(sendmail); my $email = MIME::Entity->build(Type => "multipart/alternative", To => 'somebody@example.com', subject => "Test Email"); $email->attach(Data => ["THIS IS DIRECTLY ATTACHED TEXT"], Type => "text/plain; charset=UTF-8", Encoding => "quoted-printable"); $email->attach(Data => ["<h2>THIS IS HTML TEXT<h2>"], Type => "text/html; charset=UTF-8", Encoding => "quoted-printable"); $email->print(\*STDOUT); $email->send;
When I check my email, I get only the html part to show. The plain text part disappears. However, if I remove the html part, the plain text part shows fine. Is this the right way to send combined text/html emails? I'm afraid I might be doing something stupid. The output of MIME::Entity is:
Content-Type: multipart/alternative; boundary="----------=_1455820701- +7549-0" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.414 (Entity 5.414) To: somebody@example.com Subject: Test Email This is a multi-part message in MIME format... ------------=_1455820701-7549-0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable THIS IS DIRECTLY ATTACHED TEXT= ------------=_1455820701-7549-0 Content-Type: text/html; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable <h2>THIS IS HTML TEXT<h2>= ------------=_1455820701-7549-0--
Thanks for any help!

In reply to Sending email with both html and plaintext by mavericknik

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.