Net::SMTP Can"t get AUTH working...
Net::SMTP Can"t get AUTH working...
am 02.11.2006 23:39:05 von amattina
Here is the script I am trying to get auth working with...it was
working with an open relay mail server on our internal network but I
have to have it authenticate against our ISP now so I added the auth();
to the $mail-> section of the script. Thanks!
--------
#!/usr/bin/perl -w
use strict;
use Net::SMTP;
use Getopt::Long;
use Data::Dumper;
# args are:
# -s [subject]
# [0] = recipient
# STDIN = message
my $mailhost = 'smtp.frontiernet.net';
my $from = 'email@frontiernet.net';
my $subject = undef;
my $authemail = 'usertoauth@frontiernet.net';
my $authpw = 'passwordtoauth';
my $result = GetOptions(
"subject=s" => \$subject,
"help:+" => \&usage,);
sub usage {
print " \| $0 -s \n";
print "(acts like, and is a replacement for 'mail -s')\n";
print "\n";
exit;
}
my $recipient = $ARGV[0];
my $date = scalar(localtime);
my $message = undef;
while() {
$message .= $_;
}
# check to make sure we have everything we need..
if($date and $subject and $message) {
send_mail();
} else {
if(!$date) {
die "Could not create valid date\n";
}
elsif(!$subject) {
die "Did not find mail Subject line\n";
}
elsif(!$message) {
die "No message found to send\n";
}
}
sub send_mail {
my $mail = eval { Net::SMTP->new(
Host => $mailhost,
Timeout => 30,
Hello => 'this.server',
);
};
if($@) {
die "$0 failed with message:\n$@";
}
# compose and send mail...
$mail->auth($authemail,$authpw);
$mail->mail($from);
$mail->to($recipient);
$mail->data();
$mail->datasend("From: $from\n");
$mail->datasend("To: $recipient\n");
$mail->datasend("Subject: $subject\n");
$mail->datasend("Date: $date\n\n");
$mail->datasend($message);
$mail->dataend();
$mail->quit();
return;
}
exit 0;
-----
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 08:23:42 von Sisyphus
"amattina" wrote in message
news:1162507145.827272.152470@i42g2000cwa.googlegroups.com.. .
> Here is the script I am trying to get auth working with...it was
> working with an open relay mail server on our internal network but I
> have to have it authenticate against our ISP now so I added the auth();
> to the $mail-> section of the script. Thanks!
>
I couldn't spot anything wrong with that. But let's simplify it a little. In
a situation where I need to auth(), I find the following works fine:
use warnings;
use strict;
my $ok;
my $to = 'me@optusnet.com.au';
my $from = 'sisyphus ';
my $subject = 'Test subject';
my $body = <<'EOC';
This is a test.
EOC
use Net::SMTP;
my $relay="mail.iinet.net.au";
my $smtp=Net::SMTP->new($relay);
die "Could not open connection: $!" if (! defined $smtp);
$smtp->auth("my_username", "my_password");
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$body\n");
$ok = $smtp->dataend();
if($ok) {print "All seems well\n"}
else {print "dataend() returned false\n"}
$smtp->quit;
__END__
If you change $to, $from and $relay to appropriate values - and also provide
correct arguments to auth(), then what do you get ?
Like I said, for me (having amended all of those items to appropriate
values) it works fine. It prints out "All seems well" and the message is
sent. However, if I comment out the '$smtp->auth(...);' then it prints
"dataend() returned false" and the message does not get sent.
Cheers,
Rob
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 15:34:45 von amattina
Rob,
Thanks for helping out. I feel like there is something missing in this
problem. I tried your script, and sure enough, it returned "All seems
well" but the message still did not get sent.
Sisyphus wrote:
> Like I said, for me (having amended all of those items to appropriate
> values) it works fine. It prints out "All seems well" and the message is
> sent. However, if I comment out the '$smtp->auth(...);' then it prints
> "dataend() returned false" and the message does not get sent.
I tried commenting out "$smtp->auth(..." and the script still returned
"All seems well." This does not make sense.
I setup the account in outlook as a regular POP account, with
'Authenticate with my outgoing SMTP server" and have the same values
and that works. Where is the disconnect here?
Thanks,
Adam
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 16:41:34 von Christian Winter
amattina wrote:
> Here is the script I am trying to get auth working with...it was
> working with an open relay mail server on our internal network but I
> have to have it authenticate against our ISP now so I added the auth();
> to the $mail-> section of the script. Thanks!
>
[...snipped...]
> sub send_mail {
> my $mail = eval { Net::SMTP->new(
> Host => $mailhost,
> Timeout => 30,
> Hello => 'this.server',
put in the line
Debug => 1
here to get a lot of information printed to the console, which will
hopefully include the reason your script is unable to send mails.
HTH
-Chris
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 18:15:15 von amattina
Christian Winter wrote:
> put in the line
> Debug => 1
> here to get a lot of information printed to the console, which will
> hopefully include the reason your script is unable to send mails.
>
> HTH
> -Chris
Chris,
Good call. Here is the output...with a little sanitation =D
---
/usr/bin/printf "Frontier Email test" | /usr/local/bin/perl_mailer.pl
-s "Frontier Email Test #1!" phone#@vtext.com
Net::SMTP>>> Net::SMTP(2.29)
Net::SMTP>>> Net::Cmd(2.26)
Net::SMTP>>> Exporter(5.58)
Net::SMTP>>> IO::Socket::INET(1.29)
Net::SMTP>>> IO::Socket(1.29)
Net::SMTP>>> IO::Handle(1.25)
Net::SMTP=GLOB(0x96dcf1c)<<< 220-relay01.roc.ny.frontiernet.net ESMTP
Postfix
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. FrontierNet does not authorize the
use of its computers
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. and computer networks to accept,
transmit, or distribute
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. unsolicited bulk e-mail. Effective
immediately,
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. FrontierNet may no longer accept
connections from IP
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. addresses which have no
reverse-DNS (PTR record) assigned.
Net::SMTP=GLOB(0x96dcf1c)<<< 220-.
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. For more information, visit:
Net::SMTP=GLOB(0x96dcf1c)<<< 220-. http://postmaster.frontiernet.net
Net::SMTP=GLOB(0x96dcf1c)<<< 220
Net::SMTP=GLOB(0x96dcf1c)>>> EHLO layer8noc.net
Net::SMTP=GLOB(0x96dcf1c)<<< 250-relay01.roc.ny.frontiernet.net
Net::SMTP=GLOB(0x96dcf1c)<<< 250-PIPELINING
Net::SMTP=GLOB(0x96dcf1c)<<< 250-SIZE 10240000
Net::SMTP=GLOB(0x96dcf1c)<<< 250-ETRN
Net::SMTP=GLOB(0x96dcf1c)<<< 250-AUTH LOGIN PLAIN
Net::SMTP=GLOB(0x96dcf1c)<<< 250-AUTH=LOGIN PLAIN
Net::SMTP=GLOB(0x96dcf1c)<<< 250 8BITMIME
Net::SMTP=GLOB(0x96dcf1c)>>> MAIL FROM:
Net::SMTP=GLOB(0x96dcf1c)<<< 250 Ok
Net::SMTP=GLOB(0x96dcf1c)>>> RCPT TO:
Net::SMTP=GLOB(0x96dcf1c)<<< 554 Error: The message could not be sent
because your e-mail program needs to identify itself to the sending
mail server. Please see http://support.frontiernet.net/smtp for
instructions on how to correct this setting in your e-mail program.
Net::SMTP=GLOB(0x96dcf1c)>>> DATA
Net::SMTP=GLOB(0x96dcf1c)<<< 554 Error: no valid recipients
Net::SMTP=GLOB(0x96dcf1c)>>> From: our-address@frontiernet.net
Net::SMTP=GLOB(0x96dcf1c)>>> To: phone#@vtext.com
Net::SMTP=GLOB(0x96dcf1c)>>> Subject: Frontier Email Test #1!
Net::SMTP=GLOB(0x96dcf1c)>>> Date: Fri Nov 3 12:07:19 2006
Net::SMTP=GLOB(0x96dcf1c)>>> Frontier Email test
Net::SMTP=GLOB(0x96dcf1c)>>> .
Net::SMTP=GLOB(0x96dcf1c)<<< 221 Error: Forbidden command. Goodbye.
Net::SMTP=GLOB(0x96dcf1c)>>> QUIT
Net::SMTP: Unexpected EOF on command channel at
/usr/local/bin/perl_mailer.pl line 76
---
How can I get this to work with the perl script?
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 19:16:16 von Christian Winter
amattina wrote:
> Christian Winter wrote:
>> put in the line
>> Debug => 1
>> here to get a lot of information printed to the console, which will
>> hopefully include the reason your script is unable to send mails.
>>
> Chris,
> Good call. Here is the output...with a little sanitation =D
>
[...snip...]
> Net::SMTP=GLOB(0x96dcf1c)>>> EHLO layer8noc.net
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-relay01.roc.ny.frontiernet.net
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-PIPELINING
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-SIZE 10240000
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-ETRN
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-AUTH LOGIN PLAIN
> Net::SMTP=GLOB(0x96dcf1c)<<< 250-AUTH=LOGIN PLAIN
> Net::SMTP=GLOB(0x96dcf1c)<<< 250 8BITMIME
> Net::SMTP=GLOB(0x96dcf1c)>>> MAIL FROM:
[...snap...]
Between those last two lines you should normally see something like
Net::SMTP=GLOB(0x96dcf1c)>>> AUTH LOGIN
Net::SMTP=GLOB(0x96dcf1c)<<< 334 VXNlcm5hbWU6
Net::SMTP=GLOB(0x96dcf1c)>>> eW91cnVzZXJuYW1l
Net::SMTP=GLOB(0x96dcf1c)<<< 334 UGFzc3dvcmQ6
Net::SMTP=GLOB(0x96dcf1c)>>> eW91cnBhc3N3b3Jk
Net::SMTP=GLOB(0x96dcf1c)<<< 235 Authentication successful
(the exact dialog may vary, depending on the mechanisms the
server supports for authentication), but it should end in either
"235 Authentication successful" or "535 Error: authentication failed".
Do you have both MIME::Base64 and Authen::SASL modules installed,
which are needed to do SMTP auth?
You'll see if one is missing if you modify your auth line to:
$mail->auth($authemail,$authpw)
or die "Error authenticating.: " .
$mail->code . ' ' . $mail->message;
If you get back "Error authenticating: 500 Need MIME::Base64 and
Authen::SASL todo auth" installing both (or whichever is missing)
should fix your problem.
The code() and message() methods are inherited from Net::Cmd,
just in case you're wondering where the heck I found those ;)
-Chris
Re: Net::SMTP Can"t get AUTH working...
am 03.11.2006 22:31:35 von amattina
Christian Winter wrote:
> If you get back "Error authenticating: 500 Need MIME::Base64 and
> Authen::SASL todo auth" installing both (or whichever is missing)
> should fix your problem.
Had cpan install both of those and then everything cranked though.
Thanks Chris! Great work.
Re: Net::SMTP Can"t get AUTH working...
am 04.11.2006 01:27:53 von Sisyphus
"amattina" wrote in message
news:1162564485.638094.11180@m73g2000cwd.googlegroups.com...
..
..
>
> > Like I said, for me (having amended all of those items to appropriate
> > values) it works fine. It prints out "All seems well" and the message is
> > sent. However, if I comment out the '$smtp->auth(...);' then it prints
> > "dataend() returned false" and the message does not get sent.
>
> I tried commenting out "$smtp->auth(..." and the script still returned
> "All seems well." This does not make sense.
>
It makes no sense at all to me.
I couldn't find the dataend() documentation in perldoc ... but I'm sure I
read somewhere that if it returns true then that means everything worked,
otherwise something failed.
Turn on debugging in the constructor:
my $smtp=Net::SMTP->new($relay, Debug => 1);
Perhaps that might throw up something that solves the puzzle, as it should
show you the full client-server conversation.
In my case, the mail server that needs authentication is the iinet.com.au
mail server. However, if the email I'm sending is destined for an
iinet.com.au address, authentication is not needed. It's only when the email
goes to somewhere else that authentication is needed.
But as to how dataend() can return true and the email be not sent .... beats
me.
Cheers,
Rob