简体   繁体   English

电子邮件脚本无法在IIS上运行

[英]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. 但是,当我将其放入C:\\inetpub\\wwwroot并从Web浏览器运行它时,我得到了Sending email...文本,但随后什么也没有。 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. 我不确定为什么它可以从cmd而不是从IIS运行。 Is there some extra configuration needed for the script to do this through IIS? 通过IIS进行脚本操作是否需要一些额外的配置?

I also tried with sendmail() and get similar results. 我也尝试过sendmail()并得到类似的结果。

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? 其次,您如何安装Net :: SMTP? Make sure it, and all it's dependancies have permissions by the IIS worker process. 确保它及其所有依存关系都具有IIS工作进程的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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