據傳,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