Click here to get back home

Sending Email from Perl - PLEASE help

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Sending Email from Perl - PLEASE help gpayne_onetel@hotmail.com 04-25-2006
Get Chitika Premium
Posted by gpayne_onetel@hotmail.com on April 25, 2006, 1:49 pm
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.


Posted by Jim Gibson on April 25, 2006, 7:53 pm
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);}

[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.

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



Posted by gpayne_onetel@hotmail.com on April 26, 2006, 4:47 am
Please log in for more thread options


Big thank you.

Linux server cannot communicate with mail server.
Penny dropped.


Similar ThreadsPosted
Sending mails through perl April 11, 2006, 4:22 am
Sending mails through perl April 11, 2006, 5:43 am
how to read email automatically without POP3 and IMAP servers in perl? December 13, 2004, 1:06 pm
sending an SMS message November 11, 2005, 8:15 pm
Sending output to Spreadsheet January 3, 2007, 12:22 am
trouble sending XML payload in SOAP::Lite -> .NET January 11, 2006, 10:45 am
Converting email December 21, 2004, 6:14 pm
Attaching to an email May 18, 2006, 5:59 pm
Yahoo email October 2, 2008, 10:56 am
Email::Filter hello world August 15, 2004, 3:36 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap