This wont fly: $smtp = Net::SMTP->new('$my_host'); the single quotes stop Perl from interpolating the $my_host so you are trying to connect to a host called $my_host, literally.

This sets the sender: $smtp->mail($ENV{USER}); and this sets the recipient $smtp->to($mail_to);. But beware that most public SMTP servers nowadays require a valid and full email sender address and so $env{USER} wont cut it as it is just your login name unknown to say yahoo mail server. Unless of course you are using your local mail server. But even in this case, sometimes such scripts as yours are run by cron and the username in that case may be something else than what you think you are sending out.

Also, I would check the return of each command for success before proceeding to the next, for example:

my $smtp = Net::SMTP->new('$my_host'); die "error connecting to $my_host" unless defined $smtp; $smtp->mail($ENV{USER}) or die "error issuing MAIL command: ".$smtp->m +essage(); ...

When you do all these then you have every right to declare Email sent successfully

5' Edit: for debugging purposes, one can talk to the SMTP server manually via telnet (if it does not require to talk TLS or SSL). Net::SMTP replaces the following:

telnet mysmtphost.com 25 HELO myip MAIL FROM: myemail@abc.com RCPT TO: recipient@xyz.com DATA helo there blah blah .

hacky days


In reply to Re: Email sending in Activeperl 5 on Windows by bliako
in thread Email sending in Activeperl 5 on Windows by Ekanvitha9

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.