无法使用perl Mime :: Lite发送邮件

时间:2012-04-10 07:23:03

标签: perl

我无法使用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中开发它

1 个答案:

答案 0 :(得分: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.

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