在这种情况下有几个类似的线索,但似乎通常的罪魁祸首是该人忘记安装或use
相关的包。在这种情况下,似乎并不是这样。我仔细检查以确保Email::Sender
已安装
cpan[1]> install Email::Sender
Going to read '/home/ajmills/.cpan/Metadata'
Database was generated on Fri, 18 Jan 2013 07:07:06 GMT
Email::Sender is up to date (0.120002).
cpan[2]>
我的简单程序:
use strict;
use warnings;
use Email::Sender;
my $mailer = Email::Sender->new( {
mailer => 'SMTP::TLS',
mailer_args => [
Host => 'smtp.gmail.com',
Port => 587,
User => 'xxx@gmail.com',
Password => 'xxx',
Hello => 'xxx.org',
]
} );
然后运行它:
:~$ perl email.pl
Can't locate object method "new" via package "Email::Sender" at email.pl line 5.
有什么想法吗?
答案 0 :(得分:6)
不确定,但文档说要调用Email :: Sender :: Transport :: SMTP-> new。
try {
sendmail(
$message,
{
from => $SMTP_ENVELOPE_FROM_ADDRESS,
transport => Email::Sender::Transport::SMTP->new({
host => $SMTP_HOSTNAME,
port => $SMTP_PORT,
})
}
);
} catch {
warn "sending failed: $_";
};