I've been using Net::SMTP to send an e-mail with my build results. It's been working fine for over a year. I recently setup a developer build box and I'm trying to re-use my scripts on this new machine. I'm having trouble getting Net::SMTP to work on this new machine. I keep getting the following message when I run the script and it's driving me nuts:

"Can't call method "mail" on an undefined value at C:\source\Release_Build_Scripts\sendmail2.pl line 414, <$fh> line 3."

I can't for the life of me figure out what's not working. I'm logging in as a different user on this machine than I do on my build box. So I even tried logging in as myself on this new box, and running the script, thinking maybe it was a user permission problem with the SMTP server, but I got the same error. I've ported this script to another box before so I don't know why this is any different. Any help or a point in the right direction would be greatly appreciated.

The snippet of code that uses Net::SMTP is below (I removed superfluous lines). Note that I tried inserting a print command after the "$smtp = Net::SMTP->new" line and it said that the value $smtp was undefined so I'm guessing this line is the problem. Note that the error message says line 414, it's refering to the "$smtp->mail($username)" line.
$username = $ENV{"USERNAME"}; tie @MailingList, 'Tie::File', "release_list.txt" or die "Cannot open build number file: $!"; $num_recips = @MailingList; for ($j=0; $j<$num_recips; $j++) { $tolist = $MailingList[$j]; $smtp = Net::SMTP->new('smtpmail.server.com'); $smtp->mail($username); $smtp->to($tolist); $smtp->data(); $smtp->datasend("To: $tolist\n"); $smtp->datasend("From: newuser\@server.com\n"); $smtp->datasend("Subject: Build $bldmsg\n"); $smtp->datasend("\n"); $smtp->datasend("BUILD SUMMARY:\n"); $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit; }

In reply to Trouble getting Net::SMTP to work by yankeeblue

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.