电子邮件程序无法在Perl中运行

时间:2013-10-02 02:12:05

标签: perl

我在Perl玩游戏,我写了一个小电子邮件程序。它是这样的:

# -w
#the purpose of this program is to send an email .
print "Hello. Welcome to Paramjot's Mail Program. Please enter your name.\n";
$name = <STDIN>;
chomp ($name);
print "Hello, $name. Please type in the email address you wish to send your email to\n";
$mailadds = <STDIN>;
chomp ($mailadds);              
open  MAIL, "|mail $mailadds";
print "Please type the message you wish to send below.\n";
$message = <STDIN>;
chomp ($message); 
print MAIL "$name says: $message";
close MAIL;

出于某种原因,当我运行该程序时,它一直有效,直到该程序要求该消息,而是说

mail is not recognized as a batch file, internal or external command, or an application.

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

错误消息来自您的操作系统,而不是来自Perl。

您的open语句尝试启动运行命令mail $mailadds的新进程,但由于操作系统无法识别命令mail,因此失败。要解决即时错误,您需要验证计算机上是否安装了mail(或等效程序),并更改open语句以提供该程序的完整路径和正确的文件名。

整体任务的更好解决方案是从CPAN获取邮件处理模块并使用它而不是调用外部程序。这些模块提供了更友好的界面,而且它们经常抽象出任何特定于操作系统的细节,例如确定用于发送邮件的程序的正确名称和位置。

就个人而言,我倾向于使用MIME::Lite,尽管模块的维护者建议不要使用它。链接文档包括邮件发送模块的建议,如果您选择注意他的建议而不使用MIME :: Lite,他认为这些模块是“更好的选择”。