据传,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

最新文章

  1. 感悟:搞了整整一天,拯救一个Ubuntu系统
  2. Mysql 自动增长 重置
  3. JS 禁止浏览器右键菜单和刷新
  4. editplus使用:非法字符: \65279
  5. kafka学习(二)-zookeeper集群搭建
  6. 给即将面临Noip的二班同学
  7. LNMP下基于端口的虚拟主机配置
  8. 通讯录--(适配iOS7/8/9)
  9. cycript
  10. 新浪微博Oauth2.0授权认证及SDK、API的使用(Android)
  11. 转换流 InputStreamReader
  12. Android开发者的Anko使用指南(二)之Dialogs
  13. 添加默认安全组规则-openstack
  14. system函数的应用
  15. iOS 如何优化项目
  16. $(document).ready() 和 window.onload 方法比较
  17. codevs 1052 地鼠游戏 优先队列
  18. Jquery中的has、find、filter方法区别
  19. iOS audio不支持循环播放
  20. 017random模块

热门文章

  1. Web框架之Django_08 重要组件(form组件、cookie和session组件)
  2. Hive和Hbase整合
  3. HDU 4003 Find Metal Mineral
  4. HTML5 移动端web
  5. Spring 常见错误解决方案记录
  6. 六 、harbor使用
  7. 【LeetCode】Count and Say(报数)
  8. python os模块部分摘录
  9. Java面向对象三大特征
  10. poj1717 Dominoes (背包)