|
Posted by amattina on November 2, 2006, 5:39 pm
Please log in for more thread options
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 "<message> \| $0 -s <subject> <recipient>\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(<STDIN>) {
$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;
-----
|
|
Posted by Sisyphus on November 3, 2006, 2:23 am
Please log in for more thread options
> 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 $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
|
|
Posted by amattina on November 3, 2006, 9:34 am
Please log in for more thread options
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
|
|
Posted by Sisyphus on November 3, 2006, 7:27 pm
Please log in for more thread options
.
.
>
> > 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
|
|
Posted by Christian Winter on November 3, 2006, 10:41 am
Please log in for more thread options
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
|
| Similar Threads | Posted | | SMTP::new() | October 11, 2005, 2:36 am |
| Net::SMTP | July 25, 2006, 8:44 am |
| net smtp help | October 24, 2006, 4:02 pm |
| GD not working | September 13, 2004, 2:52 pm |
| Net::Telnet and SMTP | June 13, 2005, 11:01 am |
| Question on NET::SMTP new() | October 11, 2005, 2:32 am |
| Anyone working on ALSA ? | October 5, 2007, 2:02 am |
| SMTP: "to" or/and "recipient" question. | November 11, 2005, 8:52 am |
| Installing Net::SMTP as non-root | March 19, 2007, 4:03 pm |
| "Host =>" in the Net::SMTP module | August 15, 2007, 8:37 am |
|