|
Posted by sm on April 26, 2006, 2:13 am
Please log in for more thread options
> Hi,
>
> I have written a simple script in PERL to monitor databases. The script
> sends emails via an authenticated SMTP server.
> Script works perfectly well in windows, but falls over in Linux with
> error message
>
>
> Can't call method "auth" on an undefined value at aimanage.pm line 22.
>
> Offending Line $smtp->auth( $smtpUser,$smtpPasswd);
>
> Works absolutely fine on Windows. Installed additional modules
> Net-SMTP_auth and Authen::SASL
> $smtpUser and SmtpPassword are definately defined.
>
> Any suggestion would be greatly appreciated, as this has me completely
> stumped.
>
> Whole Script as follows:
> sub send_email (@_)
> {
> my($subject,$message) = @_;
> $smtp = Net::SMTP->new($smtpHost); # connect to an SMTP server
> if ($authenicate ) { $smtp->auth( $smtpUser,$smtpPasswd);}
> $smtp->mail( $smtpFrom ); # use the sender's address here
> foreach $sendto (@smtpTo) { $smtp->to($sendto); }
> # Start the mail
> $smtp->data();
> # Send the body.
> $smtp->datasend("$message \n\n");
> $smtp->datasend("More information in the Log file \n");
> my($outline) = $dir . $logfile;
> $smtp->datasend("$outline \n");
> $smtp->dataend(); # Finish sending the mail
> $smtp->quit; # Close the SMTP connection
> }
>
> Many Thanks
>
> Gareth.
>
==========================
Here is my code that I have tested with couple ISPs.
#!/usr/bin/perl
# -*-Perl-*-
use Carp;
use Net::SMTP;
use strict;
my $msg = 'This is a simple Net::SMTP mailer test';
my $tolist = '<your email address>';
my $cclist = '';
my $logstr = 'this is the log string';
my $smtp = Net::SMTP->new('<your smtp server>',
Timeout => 30,
Debug => 1 ); # connect to SMTP server
$smtp->auth('DIGEST-MD5', # or 'CRAM-MD5' auth. method your smtp is using
'<your email address>',
'<your pass word>');
#$smtp->auth;
$smtp->mail('<your email address>'); # use the sender's adress here
$smtp->to('<recipient's email address>'); # recipient's address
$smtp->data(); # Start the mail
$smtp->datasend('testing the Net::SMTP mail\n');
$smtp->datasend('line 2\n');
$smtp->dataend(); # Finish sending the mail
$smtp->quit; # Close the SMTP connection
exit;
-sm
|