use strict; use MIME::Lite; use Net::SMTP::TLS; # Send HTML document with inline images # Create a new MIME Lite object my $msg = MIME::Lite->new( From =>'foo@gmail.com', To =>'whoever@wherever.com', Subject =>'Hi', Type =>'multipart/related'); # Add the body to your HTML message $msg->attach(Type => 'text/html', Data => qq{

Hi

This is an HTML message.

Here's a link.

}); # Attach the image $msg->attach(Type => 'image/jpg', Id => '2uni2.jpg', Path => '2uni2.jpg'); # Send it with TLS my $mailer = new Net::SMTP::TLS( 'gmail.com', Port => 465, User => 'foo', Password=> 's3cr3t'); $mailer->mail('foo@gmail.com'); $mailer->to('whoever@wherever.com'); $mailer->data; # this is where you send the MIME::Lite object $mailer->datasend( $msg->as_string ); $mailer->dataend; $mailer->quit;