• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with Perl Net::SMTP

Attrox

Golden Member
Basically I'm configuring Bugzilla to work on Windows2000. Everything else works except that I'm having problem sending e-mail.

my $smtpserver = "some.mailservername.com";
my $smtp = Net::SMTP->new($smtpserver, Debug => 1);
die "Couldn't connect to server" unless $smtp;

...some command to send the e-mail...

If I run the above code through the command line I can connect to the smtp server and send the e-mail. But when I run the script through the web browser, I always get the Couldn't connect to server error message.

Anyone has any idea on how to solve this?
 
What bugzilla script are you editing??? I have bugzilla running on Linux and don't remember having to configure this...
 
you are running this as a CGI script, and it's failing? check your apache error log for info, perhaps it's failing on a different line. Also, you need to do debug=0 when you change to web based, as it's going to send stuff to the browser, and it's expecting the "content-type" flag very first. Anything else, and your web server will (and should) puke. Put a line that says "print "Content-type text/plain\n\n" (or something like that) at the very top of your script, then it will dump the debug stuff to the browser just fine (if you are wanting that). I wrote some net::smtp scripts just the other day without any problem.
 
I'm editing BugMail.pm, and it's having the same problem so I just create a simple script to test this function.

I'm hosting the scripts using IIS on windows 2000.
 
I don't use IIS (I prefer apache on windows, if forced to use windows) so I don't know where the error log is. If it works from command line (i.e the mail is sent) but dies from CGI, make sure you turn the debug off.
 
I turned off the debug and still the e-mail is not sent at all.
I am behind my company firewall but I don't understand why I can send via command prompt but not when I run the script from the browser.

 
Doesn't IIS have an error log? You need an error log, so you can see where it's choaking. Is it erroring out on the page (i.e. 500 server error) or just never sending the email?
 
It just never send the e-mail, it didn't error out on the page.

This is the contents of the .pl file
#!C:\perl\bin\perl.exe
use strict;
use Net::SMTP;

print "Content-type text/plain\n\n";
my $smtpserver = "some smtp server";
my $smtp = Net::SMTP->new($smtpserver, debug => 1);
die "Couldn't connect to server" unless $smtp;
$smtp->mail('test@test.com');
$smtp->to('username@somecompany.com');
$smtp->data();
$smtp->datasend("To: username\@somecompany.com");
$smtp->datasend("From: test\@test.com\n");
$smtp->datasend("Subject: Test e-mail\n");
$smtp->datasend("\n");

$smtp->datasend("Hello world\n\n");
$smtp->dataend();
$smtp->quit();

Running this script from command line send the e-mail right away, no problem.
 
turn the use warnings flag on, and FIND IIS'S SCRIPT ERROR LOGS...in apache on linux, it's something like /var/logs/apache/error_log

here is the top of my script....

#!/usr/bin/perl
#Sample SMTP Script
use warnings;
use strict;
use Net::SMTP;
use CGI;
use POSIX qw(strftime);



#Setup CGI to pull the variables
my $query = CGI::new();
my $action = $query->param("action");
#my $MailFrom = $query->param("user");
my $user = $query->param("user");
my $MailFrom = "$user\@XXXX.com";
my $subject = $query->param("subject");
my $insub = $query->param("insubject");
my $iam;
my $time = strftime "%a %b %e %H:%M:%S %Y", localtime;
if ( $user eq "NULL")
{
print "Content-Type: text/html\n\n";
print "<html><HEAD>\n<TITLE>$user $action</title></head>\n";
print "<body>\n";
print "NO USER SELECTED!<br> Please go back and select a user.<br></body></html>\n";
exit(0);
}
if ( $action eq "BBIN")
{
$iam = "BBIN $insub $time";
}
if ( $action eq "BBOUT")
{
$iam = "BBOUT $subject $time";
}


my $ServerName = "10.255.31.15";

# Connect to the server
my $smtp = Net::SMTP->new($ServerName, Hello => "ms.XXXX.com") ;
die "Couldn't connect to server" unless $smtp ;
#$MailFrom = "$user\@XXXX.com" ;
my $MailTo = "alias\@XXXX.com" ;
#my $MailTo = "nweaver\@XXXX" ;
my $CC = "receptionist\@XXXX.com" ;

$smtp->mail( $MailFrom ) ;
$smtp->to( $MailTo ) ;
$smtp->cc( $CC ) ;
# Start the mail
#print "Sending Data\n";
$smtp->data() ;
# Send the header.
$smtp->datasend("To: $MailTo") ;
$smtp->datasend("From: $MailFrom\n") ;
$smtp->datasend("CC: $CC\n");
$smtp->datasend("Subject: $iam <EOM>\n") ;
$smtp->datasend("\n") ;
#
# Send the message
#$smtp->datasend("I am $iam.\n\n") ;

# Send the termination string
$smtp->dataend() ;
$smtp->quit() ;


#HTML Stuff
print "Content-Type: text/html\n\n";
print "<html><HEAD>\n<TITLE>$user $action</title></head>\n";
print "<body>\n";
#print "$host\'s $lmact";
print "$user has been reported as $action\n";
#print "\n<p>This page will go back to the main page in 3 seconds";
print "\n</body>\n";
#print "</html>\n";
print "<script language=\"javascript\">\n";
print "function redirectPage() {\n";
print " // Set the value of the href property of the location object to the address to which we want to redirect users\n";
print "document.location.href = \"/bb.html\";\n";
print " }\n";
print " // Setup our wait time\n";
print " setTimeout(\"redirectPage()\",3000);\n";
print "</script>\n";

Edit: Sanitized
 
have you tried removing the debug statement totally? I also had to add the hello statement to get our exchange server to work reliably
 
I'm sorry, I got tied up at work at the moment. I will try it maybe later today.
Thanks for the help 🙂
 
Back
Top