用Perl发送邮件小例子
2024-09-02 00:33:53
据传,Perl发送邮件有很多方案,但我只会用Mail::Sender这种方式,也就只能简单谈谈这种方式。
在参考众多网页后,程序书写如下:
#!/usr/bin/perl -w use Mail::Sender; my $sender=Mail::Sender->new({ ctype=>'text/plain;charset=utf-8', encoding=>'utf-8', smtp =>'smtp.163.com', from =>'budefiang345@163.com', auth =>'LOGIN', authid =>'budefiang345@163.com', authpwd =>'mypassword'} ) or die "Can't send mail.\n"; my $msg='Hello,this is a mail built by perl'; $sender->MailMsg({ to=>'othermail@163.com', subject=>'Perl mail sample', msg=>$msg} ); $sender->Close(); print "Mail sent!\n";
但是,程序写好后,执行#perl mail.pl,坏了,报出如下类似错误:
Can't locate Mail/Sender.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at mail.pl line 5.
BEGIN failed--compilation aborted at mail.pl line 5.
网上一查,原来是要安装perl的Mail模块,自己摸索了步骤如下:
#yum install perl-CPAN*
#cpan
cpan[1]>install Mail::Sender
cpan[2]>quit
之后Mail模块就安装好了,再执行#perl mail.pl,发现邮件已经送到指定邮箱了。
就是这些,虽然途中有点着急上火,但结果还是达成期望了。
2017年1月20日17:12:37
最新文章
- 感悟:搞了整整一天,拯救一个Ubuntu系统
- Mysql 自动增长 重置
- JS 禁止浏览器右键菜单和刷新
- editplus使用:非法字符: \65279
- kafka学习(二)-zookeeper集群搭建
- 给即将面临Noip的二班同学
- LNMP下基于端口的虚拟主机配置
- 通讯录--(适配iOS7/8/9)
- cycript
- 新浪微博Oauth2.0授权认证及SDK、API的使用(Android)
- 转换流 InputStreamReader
- Android开发者的Anko使用指南(二)之Dialogs
- 添加默认安全组规则-openstack
- system函数的应用
- iOS 如何优化项目
- $(document).ready() 和 window.onload 方法比较
- codevs 1052 地鼠游戏 优先队列
- Jquery中的has、find、filter方法区别
- iOS audio不支持循环播放
- 017random模块