我无法使用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;
Run Code Online (Sandbox Code Playgroud)
当邮件服务器与LAN连接时,上面的代码工作正常.在远程系统中使用代码时,错误已被抛出,如下所述
"SMTP Failed to connect to mail server: Bad file descriptor".
Run Code Online (Sandbox Code Playgroud)
我可以知道原因..代码是否在远程系统中运行.如果没有改变我的代码是什么..请分享您的解决方案....
提前致谢...
注意:我在Windows XP中开发它
变量不包含您认为包含的内容.如果您已打开警告,您可能会自己注意到这一点.
$ 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.
Run Code Online (Sandbox Code Playgroud)
解决方法是使用单引号来分隔这些字符串.