Apache+Perl Net::SMTP Strange problem

Z

zhaoningli

I am setting up a web application using apache 2.2 + perl v5.8.8 on
FC5. The application needs to send out email using a SMTP server as
mail relay (MTA). I wrote a test perl script test.cgi. Run the script
as CGI, it always return with errors. The code fails at:

my $smtp=new Net::SMTP($smtpserver, Timeout =>60) || die 'Cannot
connect to smtp server';

The apache server is configured to run at apache:apache. The above
script works well if I use

bash# sudo -u apache perl test.cgi.

Please advise how to fix this. Thanks a lot.
 
Z

zhaoningli

The full script I wrote is as the following:

#!/usr/bin/perl

use Net::SMTP;
use MIME::Base64;


print "Content-Type: text/html; charset=UTF-8\n\n\n";

print "\n\n<html><body>Hello</body></html>\n\n";
MessageToMTA();
exit;

sub trim {
my ($str) = @_;
if ($str) {
$str =~ s/^\s+//g;
$str =~ s/\s+$//g;
}
return $str;
}

sub MessageToMTA {
my $rcpt_to = trim('(e-mail address removed)');

my $smtp_server = '192.168.1.100';
my $smtp_user = '(e-mail address removed)';
my $smtp_pass = '123';

my $encode_smtpuser = trim(encode_base64($smtp_user));
my $encode_smtppass = trim(encode_base64($smtp_pass));

my $smtp = Net::SMTP->new($smtp_server, Timeout => 60, Debug
=> 1) || die 'Cannot connect to smtp server';

my $result = $smtp->command('AUTH', 'LOGIN');
my $answer = $smtp->getline();

$result = $smtp->command($encode_smtpuser);
$answer = $smtp->getline();

$result = $smtp->command($encode_smtppass);
$answer = $smtp->getline();

$smtp->mail($smtp_user);
$smtp->to($rcpt_to);
$smtp->data();
$smtp->datasend('here');
$smtp->dataend();
$smtp->quit;
}
 
J

J. Gleixner

First, can you send e-mail through $smtpserver directly?

Second, have die() show you why the method failed:

my $smtp=new Net::SMTP($smtpserver, Timeout =>60)
or die "Error for $smtpserver: $!";

Third, try the Debug parameter.
 
Z

zhaoningli

Problem has been resolved. Because I enabled SELiunx in FC5, if I
setenforce to 0, there will be no problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top