CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Stumped by Net::SMTP

 



mrice1
Novice

Dec 28, 2011, 12:09 PM

Post #1 of 12 (3740 views)
Stumped by Net::SMTP Can't Post

I keep getting:
Can't call method "mail" on an undefined value at mail.pl line 13.

Line 13 is:
$smtp->mail($from);


$from is defined in line 9:
my $from='<my email>';

Can anyone help me figure out what I've missed?


FishMonger
Veteran / Moderator

Dec 28, 2011, 12:48 PM

Post #2 of 12 (3737 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

It's telling you that $smtp is not defined.


mrice1
Novice

Dec 28, 2011, 12:52 PM

Post #3 of 12 (3735 views)
Re: [FishMonger] Stumped by Net::SMTP [In reply to] Can't Post

I've got:

use Net::SMTP;
my $server='<My smtp server>';
my $from='<my email>';
my $to='<target email>';
$smtp = Net::SMTP->new($server);
$smtp->mail($from);

I have also tried:
use Net::SMTP;
$smtp = Net::SMTP->new('<my smpt server>');
$smtp->mail('<my email>');


FishMonger
Veteran / Moderator

Dec 28, 2011, 1:02 PM

Post #4 of 12 (3733 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

Enable debug and see what it tells you.


mrice1
Novice

Dec 28, 2011, 2:56 PM

Post #5 of 12 (3722 views)
Re: [FishMonger] Stumped by Net::SMTP [In reply to] Can't Post

The only thing odd I've found so far is that, when I put a watch on $smtp it does not stop at the line where I define $smtp to tell me that the value has changed:

$smtp = Net::SMTP->new($server);


FishMonger
Veteran / Moderator

Dec 28, 2011, 5:39 PM

Post #6 of 12 (3717 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

You didn't enable debug as I suggested.


Code
$smtp = Net::SMTP->new($server, Debug => 1);


Does your server require authentication or is it wide open and allows anyone/everyone to relay email?


mrice1
Novice

Dec 29, 2011, 7:52 AM

Post #7 of 12 (3686 views)
Re: [FishMonger] Stumped by Net::SMTP [In reply to] Can't Post

I misunderstood. I ran the script with -d option. Here's what I got with the Debug => 1:

Net::SMTP: Net::SMTP(2.15)
Net::SMTP: Net::Cmd(2.18)
Net::SMTP: Exporter(5.562)
Net::SMTP: IO::Socket::INET(1.25)
Net::SMTP: IO::Socket(1.26)
Net::SMTP: IO::Handle(1.21)

Net::SMTP: Unexpected EOF on command channel at mail.pl line 13

----------------------------------------
Authentication ... well duh. That's something kinda basic I forgot.


mrice1
Novice

Dec 29, 2011, 10:48 AM

Post #8 of 12 (3681 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

Authentication didn't seem to help:


Can't call method "auth" on an undefined value at mail.pl line 14.


FishMonger
Veteran / Moderator

Dec 30, 2011, 7:29 AM

Post #9 of 12 (3676 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

That's telling you that your object creation is still failing.

Did you supply the "Hello" option?

When defining the $server, $from and $to vars, are you including the < > angle brackets like you have in your posted code snippet?


mrice1
Novice

Dec 30, 2011, 7:47 AM

Post #10 of 12 (3674 views)
Re: [FishMonger] Stumped by Net::SMTP [In reply to] Can't Post

No, no angle brackets in the code.

I downloaded Mail-Outlook at home and manually installed in. PPM and our firewall don't get along. It's working now re-written for the Outlook module but if you've got any more tips about what I was doing wrong there I'd be grateful to learn something.


FishMonger
Veteran / Moderator

Dec 30, 2011, 8:19 AM

Post #11 of 12 (3673 views)
Re: [mrice1] Stumped by Net::SMTP [In reply to] Can't Post

This connection snippet works for me.

Code
#!/usr/bin/perl 

use strict;
use warnings;
use Net::SMTP;

my $server = 'my_smtp_srv_hostname';
my $from = 'me@mycompany.com';
my $to = 'someone@anothercompany.com';
my $smtp = Net::SMTP->new($server,
hello => $from,
Debug => 1);

die unless $smtp;
print "established smtp connection\n";


If it doesn't for you, then maybe you need to have some proxy settings configured?


mrice1
Novice

Dec 30, 2011, 8:56 AM

Post #12 of 12 (3671 views)
Re: [FishMonger] Stumped by Net::SMTP [In reply to] Can't Post

Pretty much the same result using your code:
Net::SMTP: Unexpected EOF on command channel at mailtest.pl line 8
Died at mailtest.pl line 12.



Proxy settings while I'm inside the firewall? Both the two and from emails are within the company and both PC's are inside as well.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives