简体   繁体   English

使用Perl发送电子邮件时未安装sendmail且没有任何邮件模块

[英]Sending an email with Perl without sendmail installed and without any mail modules

I am making a website for a camping and I need to send an email from Perl. 我正在建立一个露营网站,我需要发送一封来自Perl的电子邮件。 However, sendmail is not installed on the server, and these are the only Perl modules installed: 但是,服务器上未安装sendmail ,这些是唯一安装的Perl模块:

  • Class::Accessor 类::访问器
  • Config::Tiny 配置::微小
  • Math::Calc::Units 数学::计算器::单位
  • Nagios::Plugin Nagios的::插件
  • Params::Validate PARAMS ::验证
  • Perl 5.8.8 Perl 5.8.8
  • TimeDate TIMEDATE

Is there still a way to send an email form a Perl script? 还有办法从Perl脚本发送电子邮件吗?


I already phoned the webhosting company about this but it seems that they don't even know what Perl is. 我已经打电话给网站主办公司,但似乎他们甚至都不知道Perl是什么。 Let alone sendmail . sendmail别说了。 That calls itself a webhosting company. 这称自己是一家虚拟主机公司。

This question can be rephrased more generically as "how can I do something in Perl that requires a module that isn't installed on my system, and I don't have root control over this box and sysadmins can't or won't cooperate?" 这个问题可以更普遍地重新描述为“如何在Perl中执行某些需要未安装在我的系统上的模块的东西,而且我没有对此框的根控制,并且系统管理员不能或不会合作?”

In one sentence, the best answer is "use local::lib ", but you can read more options in Matt Trout's blog post "But I can't use CPAN!" 在一句话中,最好的答案是“使用local :: lib ”,但你可以在Matt Trout的博客文章“但我不能使用CPAN”中阅读更多选项 .

Net::SMTP is a core module and should be included in any installation of Perl. Net :: SMTP是一个核心模块,应该包含在任何Perl安装中。 The module documentation shows a simple example of sending an email. 模块文档显示了发送电子邮件的简单示例。 Use "perldoc Net::SMTP" to see if it is there and to see the example. 使用“perldoc Net :: SMTP”查看它是否存在并查看示例。

Apart from the obvious answer (“change your hoster”), sure, you can write an SMTP client in bare perl. 除了明显的答案(“更改你的主机”),当然,你可以用裸perl写一个SMTP客户端。 The easiest way to do that would be to integrate Net::SMTP or, for something a little fancier, Email::Send into your perl code. 最简单的方法是集成Net::SMTP或者对于一些有点爱好者的东西,将Email::Send集成到你的perl代码中。 Pure Perl modules don't need any special installation process. Pure Perl模块不需要任何特殊的安装过程。 But it is not hard to write an SMTP client from scratch, either. 但是从头开始编写SMTP客户端也不难。

Whichever you choose, make sure to insert some way of retrying after an hour or so upon failure. 无论您选择哪种方式,请确保在发生故障后一小时左右插入一些重试方式。 Else, your site will go among those web sites which simply cannot send mail to anyone using greylisting . 否则,您的网站将进入那些无法向使用灰名单的人发送邮件的网站。

Find a new hosting company? 找一个新的托管公司? Or at least host your email form somewhere else? 或者至少在其他地方托管您的电子邮件表格?

If you have access to the shell you should be able to install a module in the local folder. 如果您有权访问shell,则应该能够在本地文件夹中安装模块。 Barring that you might even be able to "install" a pure perl module on some other machine and then copy the resulting module via FTP to the host. 除非您甚至可以在其他计算机上“安装”纯perl模块,然后通过FTP将生成的模块复制到主机。

As for the module you should use: MIME::Lite can send using SMTP so sendmail isn't required. 至于你应该使用的模块:MIME :: Lite可以使用SMTP发送,因此不需要sendmail。 It's also all perl (no C backend) so you can probably get that going. 它也都是perl(没有C后端)所以你可能会这样做。

If none of the above works you could connect to an SMTP server directly but that's pretty complex especially if you want to send attachments 如果以上都不起作用,您可以直接连接到SMTP服务器,但这非常复杂,尤其是当您要发送附件时

如果您无法安装任何其他模块,那么简单的方法是将sendmail模块的代码源集成到您的项目中,但您还必须检查sendmail模块的许可是否允许您这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM