Using <cpan://Net::SMTP> will work fine.
It is the nature of internet e-mail that you set the
from and
to twice if you do
raw SMTP; once in the e-mail header
and once in the SMTP session. There's a good O'Reilly
book
Programming Internet Email that goes into
all the nasty details of this stuff.
Here's an example from a piece of my
code. In this case I uses MIME::Lite to do the actual
encoding, but the process should be the same with MIME::Entity.
I've removes the error checking in the Net::SMTP communication
to make the code smaller and easier to post; you should
add the error checking back if you plan to use Net::SMTP. One other note
is that MIME::Lite has its own send method that will
send the message. So unless you need (or want) to do the SMTP
negotiation yourself, MIME::Lite may be an easier solution
for you as it can encode, add attachments and send the message.
use Net::SMTP;
use MIME::Lite;
my $from='foo@testdomain.com';
my $to='bar@testdomain.com'
my $msg_html_rich = new MIME::Lite(
From => $from,
Subject => 'MIME::Lite Test',
To => $to,
Type => 'multipart/alternative');
attach $msg_html_rich
Type =>'text/plain',
Data =>'message in plain text';
attach $msg_html_rich
Type =>'text/html',
Data =>'message in <b>HTML</b> with <i>many</i> markup tags';
my $smtp= Net::SMTP->new('127.0.0.1',
Timeout => 180);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend($msg_html_rich->as_string);
$smtp->dataend();