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();

In reply to Re: SMTP client. by lhoward
in thread SMTP client. by Punto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.