trebor has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to use MIME::Lite::TT::HTML module to send out HTML email only but for some reason I have been unsuccessful.

The mail sent using MIME::Lite::TT::HTML is showing as both plain text and HTML at the same time.

How do I prevent MIME::Lite::TT::HTML from sending plain text version of email?

OR

How do I prevent the plain text version from showing up in the email?


Source of Script
--------------------------------------------
#!/usr/bin/perl use strict; use warnings; use MIME::Lite::TT::HTML; use MIME::Base64; use HTML::Template; my %params; $params{firstname} = 'MyFirstName'; $params{lastname} = 'MyLastName'; my %options; $options{INCLUDE_PATH} = '/path/to/template'; my $msg = MIME::Lite::TT::HTML->new( From => 'email@domain.com', To => 'otheremail@otherdomain.com', Subject => 'Test 1', Type => 'multipart/mixed', HTMLEncoding => 'base64', Template => { text => 'blanktemplate.html', html => 'template.html', }, TmplOptions => \%options, TmplParams => \%params ); $msg->attach( Type =>'image/png', Path =>'/path/to/image/image.png', Id =>'img1' ); $msg->send('smtp', 'smtp.somedomain.com', Debug=>1, Timeout => 60 );

Replies are listed 'Best First'.
Re: How do I send ONLY HTML mail using MIME::Lite::TT::HTML
by Khen1950fx (Canon) on Mar 06, 2012 at 21:15 UTC
    I'd do it like this:
    #!/usr/bin/perl use strict; use warnings; use MIME::Lite::TT::HTML; my %params; $params{firstname} = 'MyFirstName'; $params{lastname} = 'MyLastName'; my %options; $options{INCLUDE_PATH} = '/path/to/template'; my $msg = MIME::Lite::TT::HTML->new( From => 'email@domain.com', To => 'otheremail@otherdomain.com', Subject => 'Test 1', Timezone => 'UTC', Type => 'multipart/related', Encoding => 'base64', Template => { html => 'template.html', }, Charset => 'utf8', TmplOptions => \%options, TmplParams => \%params, ); $msg->attach( Type => 'text/html', Data => qq{ <body> Here is <i>my</i> image: <img src="cid:image.png"> </body> }, ); $msg->attach( Type => 'image/png', Path => '/path/to/image/image.png', Id => 'img1', ); $msg->send( 'smtp', 'smtp.somedomain.com', Debug => 1, Timeout => 60, );
      Thanks. Will give that a try.

      I took a look at the module itself and I see that I could just get rid of the portion of the script that generates the text version of the email. Not the best solution I know.

      I have another problem relating to MIME::Lite::TT::HTML

      I am able to send email using MIME::Lite::TT::HTML from my web server to my domains on my email server, the servers are on separate physical boxes, but I am unable to send email from the web server to domains outside my network.

      For example MIME::Lite::TT::HTML will send email from my web server to myusername@mydomainname.com which is on my mail server but MIME::Lite::TT::HTML will not send mail from my web server to say someuser@gmail.com or anotherusername@aol.com

      Error from Logfile:

      Wed Mar 07 10:53:06 2012 error client abc.abc.abc.abc MIME::Lite::SMTP=GLOB(0x34bf960)>>> MAIL FROM:<getaninvite@somedomain.com>\r, referer: http://www.somedomain.com/invite.html
      Wed Mar 07 10:53:06 2012 error client abc.abc.abc.abc MIME::Lite::SMTP=GLOB(0x34bf960)<<< 250 2.1.0 Ok, referer: http://www.somedomain.com/invite.html
      Wed Mar 07 10:53:06 2012 error client abc.abc.abc.abc MIME::Lite::SMTP=GLOB(0x34bf960)>>> RCPT TO:<someuser@aim.com>\r, referer: http://www.somedomain.com/invite.html
      Wed Mar 07 10:53:07 2012 error client abc.abc.abc.abc MIME::Lite::SMTP=GLOB(0x34bf960)<<< 554 5.7.1 <someuser@aim.com>: Relay access denied, referer: http://www.somedomain.com/invite.html
      Wed Mar 07 10:53:07 2012 error client abc.abc.abc.abc SMTP recipient() command failed: , referer: http://www.somedomain.com/invite.html


      WEBSERVER < -----------> Router / Firewall <----------> Internet
                                                             |
                                                             |
      MAILSERVER <------------------>|


      I hope someone can point me to a quick fix so I can move on from here.

      Thanks again for your help.