Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another NET::SMTP problem...

Status
Not open for further replies.

tviman

Programmer
Jul 25, 2002
2,123
US
I'm trying, for the first time, to use NET::SMTP instead of SENDMAIL. However, I'm getting frustrated with my efforts despite the accumulating beer bottles on my desk...

This is the script I've been working with:

Code:
#!usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP;

my $smtp_server = 'mail.mydomain.com';
my $smtp = Net::SMTP->new($smtp_server);

print "Content-type: text/html\n\n";

$smtp = Net::SMTP->new($smtp_server, Debug=>1);
$smtp->mail("info\@mydomain.com");
$smtp->to("fred\@frick.com");
$smtp->data();
$smtp->datasend("Hello!\n\n");
$smtp->dataend();
$smtp->quit();

This is what is in my error logs when I run this script:

[Thu Apr 08 15:04:55 2004] [error] [client 12.34.567.890] Premature end of script headers: testmail.cgi
[Thu Apr 08 15:04:55 2004] [error] [client 12.34.567.890] failed to open log file /var/log/httpd/suexec_log
[Thu Apr 08 15:04:55 2004] [error] [client 12.34.567.890] fopen: Permission denied

So then I tried this:

Code:
#!usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP;
use MIME::Base64;

my $smtp_server = 'mail.mydomain.com';
my $smtp = Net::SMTP->new($smtp_server);
my $user = "username";
my $pass = "password";
# One way
my $auth_string = encode_base64("$user\0$user\0$pass");$smtp->command('AUTH', 'PLAIN', $auth_string);

print "Content-type: text/html\n\n";

$smtp = Net::SMTP->new($smtp_server, Debug=>1);
$smtp->mail("info\@mydomain.com");
$smtp->to("fred\@frick.com");
$smtp->data();
$smtp->datasend("Hello!\n\n");
$smtp->dataend();
$smtp->quit();

Still get the same error in the logs as above. It's been a long day and my eyeballs hurt. I'd really appreciate it if someone could give me a hint so I can attack it fresh in the morning.

Thanks so much!

Patrick

There's always a better way. The fun is trying to find it!
 
Patrick,
Surprised at you...
rolling your own headers...

Check your print statement
--Paul

 
Paul,

Thanks for clearing my head - I copied this script from one in I found in a keyword search here and didn't look at it that close.

I changed the script to this:

Code:
#!usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP;
use MIME::Base64;

[COLOR=red]my $q = new CGI;[/color]
my $smtp_server = 'mail.mydomain.com';
my $smtp = Net::SMTP->new($smtp_server);
my $user = "username";
my $pass = "password";
my $auth_string = encode_base64("$user\0$user\0$pass");$smtp->command('AUTH', 'PLAIN', $auth_string);

[COLOR=red]print q->header();[/color]

$smtp = Net::SMTP->new($smtp_server, Debug=>1);
$smtp->mail("info\@mydomain.com");
$smtp->to("fred\@frick.com");
$smtp->data();
$smtp->datasend("Hello!\n\n");
$smtp->dataend();
$smtp->quit();

but it isn't making any difference. Guess I'll go back to the drawing board and take it one step at a time.

Thanks for your help!

There's always a better way. The fun is trying to find it!
 
Can you run it from the command line? It looks like it's a a problem with apache's suexec, as the errors say, rather than a problem with the script itself.

 
philote - I'm running this through a web hosting service so command line execution isn't an option. I backed the script down to the bare essentials and still received errors so I put it in the SA's lap. They say that they have NET::SMTP so I gave them the error logs and the script and asked them to figure it out. When I get an answer, I'll post it here.

Thanks for your help!

There's always a better way. The fun is trying to find it!
 
Okay - got it figured out - and I am so embarressed to tell you what it was...

I had the wrong path to perl in my shebang!!!! Works fine now.

Thanks again everyone! And feel free to beat me up about it! I deserve it...

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top