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!
-
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.