« Delusinal ebay woman | Main | Band Aid »

MIME::Lite and multipart/alternative

This is probably common knowledge with techies, but for casual perl hackers like myself I thought this was a nice module.
We have a mailing list, but didn't have the foresight to categorise it into HTML and text only emails, so I needed to send an email using the multipart/alternative format (thanks Duggie and Colm). I read some of the MIME documentation and this nice intro..
http://www.zend.com/zend/spotlight/sendmimeemailpart1.php, but it was clunky and awkward.
I got the MIME::Lite module installed and it appears to work very well.
I have tested the output on a few mail clients that I have access to pine,mutt,outlook,pegasus and ultrafunk popcorn, and the desired result is very nice. Plain text for text only clients and nice pretty (management speak) html emails for the others.
How nice and simple is this:

my $msg = MIME::Lite->new(
From =>$from,
To =>$toaddress,
Subject =>"Campus One newsletter",
Type =>'multipart/alternative');
$msg->attach(Type => 'text/plain', Data => qq{ @plain_text });
$msg->attach(Type => 'text/html', Data => qq{ @htmllines });
$msg->send();

I just read two files into two arrays, one file is the html the other is plain text, attach them to the msg I have created, let the module do all the hard part of building boundaries etc, and just use the send method of the MIME::Lite module, I don't even need to tell it to what way to send the mail, it finds sendmail and sends the message.
I like this wee module.