Sending Email from Perl - PLEASE help

Sending Email from Perl - PLEASE help

am 25.04.2006 19:49:36 von gpayne_onetel

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.

Re: Sending Email from Perl - PLEASE help

am 26.04.2006 01:53:25 von Jim Gibson

In article <1145987376.722945.130350@v46g2000cwv.googlegroups.com>,
<"gpayne_onetel@hotmail.com"> wrote:

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

[rest snipped]

> }

The Net::SMTP->new method is returning undef, which probably means it
is unable to connect to the SMTP host. Try adding ', Debug => 1' to the
argument list for new. Perhaps you have some connectivity problems
between the Linux system and the SMTP host that you do not have on the
Windows system.

Re: Sending Email from Perl - PLEASE help

am 26.04.2006 08:13:24 von SM

wrote in message
news:1145987376.722945.130350@v46g2000cwv.googlegroups.com.. .
> 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 = '';
my $cclist = '';
my $logstr = 'this is the log string';

my $smtp = Net::SMTP->new('',
Timeout => 30,
Debug => 1 ); # connect to SMTP server

$smtp->auth('DIGEST-MD5', # or 'CRAM-MD5' auth. method your smtp is using
'',
'');

#$smtp->auth;
$smtp->mail(''); # use the sender's adress here
$smtp->to(''); # 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

Re: Sending Email from Perl - PLEASE help

am 26.04.2006 10:47:31 von gpayne_onetel

Big thank you.

Linux server cannot communicate with mail server.
Penny dropped.