1

我无法使用 MIME::Lite 发送邮件。从我的桌面发送时,它会出现以下错误。错误:“SMTP 无法连接到邮件服务器:文件描述符错误”

我正在使用下面提到的代码。

use strict;
use MIME::Lite;
use Net::SMTP;

my $from_address = "no-reply@host.com";
my $to_address = "madhan@host.com";
my $cc_address = "madhan@host.com";
my $subject = "Test mail";
my $message_body = "Madhan test mail";
my $namer="madhankumar";
my $regards="Madhan M";

print " Sending mail from $from_address to $to_address \n";
my $person_name=ucfirst($namer).",";
my $mail_host = 'mail1.somehost.com';


my $msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Cc => $cc_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

$msg->attach (
  Type => 'TEXT',
  Data => "Dear $person_name\n\n".$message_body."\n\nRegards,\n$regards"
) or die "Error adding the text message part: $!\n";

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
  $msg->send;

当邮件服务器与 LAN 连接时,上述代码工作正常。在远程系统中使用代码时,已引发错误,如下所述

"SMTP Failed to connect to mail server: Bad file descriptor".

我可以知道原因.. 代码是否在远程系统中运行。如果不是我对代码所做的更改..请分享您的解决方案....

提前致谢...

注意:我在 Windows XP 中开发这个

4

1 回答 1

6

变量不包含您认为它们包含的内容。如果您打开了警告,您会自己注意到这一点。

$ perl -e'use warnings; my $from_address = "no-reply@host.com";'
Possible unintended interpolation of @host in string at -e line 1.
Name "main::host" used only once: possible typo at -e line 1.

补救方法是使用单引号来分隔这些字符串。

于 2012-04-10T08:42:04.693 回答