Unable to send a mail using perl Mime::Lite

江枫思渺然 提交于 2021-01-28 05:36:08

问题


I am unable to send a mail using MIME::Lite. While sending from my desktop it will through the below errors. Error: "SMTP Failed to connect to mail server: Bad file descriptor"

I am using the below mentioned code.

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;

The above code is working fine while the mail server is connected with LAN. While using the code in remote system the error has been thrown as mentioned in below

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

May I know the reason.. Is the code run in remote system. If not what are the change I have made the code.. Please share your solutions....

Thanks in advance...

Note: I am developing this in Windows XP


回答1:


The variables do not contain what you think they contain. If you had switched on warnings, you would have noticed this on your own.

$ 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.

The remedy is to use single quotes to delimit those strings.



来源:https://stackoverflow.com/questions/10084715/unable-to-send-a-mail-using-perl-mimelite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!