Link to home
Start Free TrialLog in
Avatar of p1800volvo
p1800volvo

asked on

use Net::SMTP; script error

I am getting an error when running this script. I am running Active State on Win2K. What am I doing wrong? Code from Perl for Sys Admin, O'Reilly Press, page 256.

Here is the error.

D:\pl>perl -w PURGE.pl
Useless use of a variable in void context at PURGE.pl line 50.
Useless use of a constant in void context at PURGE.pl line 50.
syntax error at PURGE.pl line 50, near ""Unable to create new mailer
 object";"
Execution of PURGE.pl aborted due to compilation errors.

Here is the code...

use Net::SMTP;

if(-e $INFILE) { print "OK\n" } else {
      
      ### Create an e-mail message here.

      $from="server\@abc.com";
      $to="user\@abc.com";
      $subject="Windows Purge Error";
      $body="There is a Purging Error on Win2000 server.\n";

      $type="smtp";
      $server="smtp.mahapps.inside.ups.com";
      
      my $mailer = Net::SMTP->new($type, Server => $server or
(This is Line 50)      die "Unable to create new mailer object:$!\n";

      $mailer->open({From => $from,
                  To => $to,
                  Subject => $subject}) or
            die "Unable to populate mailer objects part 2:$!\n";

};

I tried use MIME::Lite;, but got this error...

D:\pl>perl -w PURGE_ATTACHMENTS.pl
Can't locate MIME/Lite.pm in @INC (@INC contains: C:/Program Files/Perl/lib C:/P
rogram Files/Perl/site/lib .) at PURGE_ATTACHMENTS.pl line 25.
BEGIN failed--compilation aborted at PURGE_ATTACHMENTS.pl line 25.

Thanks!!!
Avatar of Tintin
Tintin

Should be:

my $mailer = Net::SMTP->new($type, Server => $server) or die "Unable to create new mailer object:$!\n";

SOLUTION
Avatar of Sergy Stouk
Sergy Stouk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of p1800volvo

ASKER

When I run the fix (stupid me) from Tintin, I get...

D:\pl>perl PURGE_ATTACHMENTS.pl
Can't locate object method "open" via package "Net::SMTP" at PURGE_ATTACHMENTS.pl line 53.

When I run the script from sstouk, I get...


D:\pl>perl PURGE_ATTACHMENTS.pl
Can't call method "mail" on an undefined value at PURGE_ATTACHMENTS.pl line 68.

Thanks people!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tested the script that I posted and it worked ASIS, of course you have to put correct SMTP Server to connect to and your own e-mail addresses.
The Error you've got is because either you specified an incorrect name for your SMTP server, or there is no connection to it or it requires Authentication (user and password) to send e-mail.
If you have any experience with Telnet  (it is available in Windows) then you can attempt to connect to the SMTP Server using port 25 and manually attempt to see its responces and if it is alive or it requires any authentication. I am sure you can find examples of responces to send to it via telnet by searching Google.
I am positive that there is nothing wrong with the example I offered above.
"Unable to create new mailer object" it is. Oh well. Guess I will have to script a conversation like sstouk said. How does that work? Do I have to call a separate script?
I did file lite.pm in the following directories...

C:\Program Files\Perl\site\lib\SOAP, ~\UDDI, ~\win32\OLE, ~\XML\Parser and ~\XMLRPC. Is there a bad or incomplete path setting, or are these versions not the required Mime::Lite?

Thanks again!
Hold off for now, I have Mime::Lite working. I will work on the points tonight.

Thanks for the great help.
50 for Tintin for the correct answer, avan though my machine did not have sendmail on it. Not his fault!

25 for sstouk foranother good example. I might use either in the future.