Perl: Sendmail - Permission denied

Hi,

I'm trying to write a simple mail handler perl script for a website I'm working on. I've managed to installed sendmail yesterday, and I'm currently trying to get the script to work. I'm getting an error however.

Here's the block of perl code I'm using:

open(MAIL, "| $sendmailpath -t") || print "Error Opening mail: $!";
print MAIL "To: my\@e-mail.com";
print MAIL "Reply: $sender_mail";
print MAIL "Subject: $sender_subj";
print MAIL "\n";
print MAIL "$sender_msg";
close MAIL || print "Error Closing mail: $!";

The error I'm getting is "Error Opening Mail: Permission Denied". I'm not trying to run a mailserver or anything, I just want to send email from a webpage.

I'm assuming it's a user/group/permission problem, since the sendmail program is being run by the webscript. However, this is my first time working with sendmail, and I have no idea what the correct settings should be.

Hi,
Chance is you might already have this package Net::SMTP - perldoc.perl.org try it, its the same as yours but avoid invoking sendmail binary directly IMHO. Anyway you can download it on Net::SMTP - Simple Mail Transfer Protocol Client - search.cpan.org

So what's in $sendmailpath?

The $sendmailpath contains /usr/sbin/sendmail.

When using Net::SMTP I need to connect to an SMTP server though correct? I'm trying to avoid this here.

Thats correct, but /usr/sbin/sendmail will talk to a SMTP server as well unless the recipient is on your localhost. And if its on another host then you defenitly need to speak to a smtp server, your mail gateway, (either with /usr/bin/sendmail or any other client Net::SMTP) that will deliver that mail to the recipient...

Alright, perhaps I should try to send it through my ISP's smtp server. I'm running this webform on my own home system. But, don't I have to enter a login and password for the smtp server? how would I do that with Net::SMTP?

Nope, you're not required to use authentication to send mail only retreiving would ... and you even wont need you're ISP mail gateway.
Here's a sample code:

#!/usr/bin/perl -w

use Net::SMTP;

$smtp = Net::SMTP->new("recipent.server.com",Hello => 'yourdomain.com');
$smtp->mail("fromyou@yourdomain.com");
$smtp->to("user1@server.com");
$smtp->cc("foo@server.com");
$smtp->data;

$smtp->datasend("From: fromyou\@yourdomain.com");
$smtp->datasend("To: user1\@server.com");
$smtp->datasend("Subject: This is a test");
$smtp->datasend("\n");

$smtp->datasend("Body Of The Mail");

$smtp->dataend;
$smtp->quit;

Hope that helps! Assuming the host you're sending mail from is connect on the net ...

Thanks for all the help andryk. I got it working now.
Now all I have to do is validate user input. :wink: