0

在这方面有几个类似的线程,但似乎通常的罪魁祸首是该人忘记安装或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.

任何的想法?

4

1 回答 1

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: $_";
  };

http://metacpan.org/pod/Email::Sender

于 2013-01-18T20:04:38.057 回答