Perl and MIME::Lite (email) help, please?

I’m trying to set up a Perl script to send out a multipart email consisting of text and html. I’m using Perl and the Mime::Lite module.

The script that I have is as follows:


use strict;
use warnings;
use MIME::Lite;

use Net::SMTP;

my $msg;

my $MAIL_RELAY = '';
my $MAIL_TIMEOUT = 60;

my $text;
my $html;
my $from = '';
my $to = '';

$text = "Mary had a little lamb with mint jelly";
$html = '<table><tr><td>cell 1</td><td>cell2</td></tr><tr><td>Cell 3</td><td>Cell 4</td></tr></table>';
$msg = MIME::Lite->new(
                 From     =>$from,
                 To       =>$to,
                 Subject  =>'test',
                 Type     =>'multipart/alternative',
## text portion
      $msg->attach(Type     =>'text/plain',
                 Data =>$text

## html portion
    $msg->attach(Type     =>'text/html',
                 Data =>$html

    		my $smtp;
	   	for (my $counter=1; $counter<=3; $counter++) {
     			$smtp = Net::SMTP->new($MAIL_RELAY);
     			if (defined $smtp) {last}
	     		else {warn "=>Could not connect to mail host \"$MAIL_RELAY\" on attempt No. $counter. Info: $!
" };
	     			sleep 5; #  wait a few seconds before trying again
		## if a valid connection to a mail server exists, email the log file
		if ($smtp) {
			MIME::Lite->send('smtp', $MAIL_RELAY, Timeout=>$MAIL_TIMEOUT) || die "Could not send mail!!";
			$msg->send || die "Could not send mail!!";

The problem is that it’s not sending both parts of the message. In fact, it’s only sending the HTML version, not the text. The proof of this is that if I switch around the two $msg->attach statements, then I only get the text part. I’ve been at this and cannot figure out what I’m doing wrong. Can anyone here help me? Please?

Zev Steinhardt

I don’t have an answer for you (as I’ve never used MIME::Lite) but you might want to try your question at Perl Monks.

Maybe your ISP is filtering scripts. Mine disables anything that looks like a script for me.

What are you using to read the results? WAG: make sure it’s actually your script and not your user-agent that’s buggy. What happens when you set the MIME type to ‘multipart/related’?