简体   繁体   中英

Email script not working on IIS

I have the following test script to send an email:

use strict;
use Net::SMTP;

print "Content-Type: text/plain\n\n";
print "Sending email...\n";

my $smtp = Net::SMTP->new('10.0.0.1', Port => 25, Timeout => 10, Debug => 1);
$smtp->mail("user1\@domain.local");
$smtp->to("user2\@domain.local");
$smtp->data();
$smtp->datasend("From: user1\@domain.local\n");
$smtp->datasend("To: user2\@domain.local\n");
$smtp->datasend("Subject: Test\n\n");
$smtp->datasend("Testing 1 2 3\n");
$smtp->datasend();
$smtp->quit;

It works fine when I run it from the command line, I get the email right away. But when I put it in C:\\inetpub\\wwwroot and run it from a web browser, I get the Sending email... text but then nothing. No email is sent, no error message is shown. I looked at the mail server log and no connection is even made. I'm not sure why it's working from cmd but not from IIS. Is there some extra configuration needed for the script to do this through IIS?

I also tried with sendmail() and get similar results.

First of all, add the following headers to the file

use strict 'vars';
use warnings;
use diagnostics;
use feature qw/say/;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

... your code...

# Print Warnings
warningsToBrowser(1);

That will give you more information if it's failing or throwing a warning on something.

Secondly, how did you install Net::SMTP? Make sure it, and all it's dependancies have permissions by the IIS worker process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM