开发者

Which package from CPAN should I use to send mail?

开发者 https://www.devze.com 2023-01-01 00:46 出处:网络
Which package from CPAN should I use to send mail? Sometime the timtowtdi approach is very tiring. For me, especially when it comes to package selection.

Which package from CPAN should I use to send mail?

Sometime the timtowtdi approach is very tiring. For me, especially when it comes to package selection.

So all I want is to send email, potentially HTML emails. Between Mail-Sendmail, Mail-Sender, NET-SMTP (by the way - not available in PPM), Mail-SendEasy, and the 80 or so other packages that have 'Mail' in their package name - which one should I choose?

And while in this s开发者_如何转开发ubject, what is your general apprach to choose the "canonical" package for a jog. I.e. the package that "everybody is using". Is there any rating or popularity billboard somewhere?


what is your general apprach to choose the "canonical" package for a jog. I.e. the package that "everybody is using". Is there any rating or popularity billboard somewhere?

When I want to pick which of several CPAN modules to use, the things I look at are

Documentation:

The litmus test for CPAN modules is the first page of the documentation. If there is a messy synopsis, or a synopsis without a simple working example, I guess that the module is probably not a good one. Untidy, messy, or misformatted documentation is also a red flag.

State of repair:

  • the date of release of the last version of the module tells you if it is being maintained,
  • the CPAN tester's reports tell you whether the module is likely to install without a struggle
  • the bugs list on rt.cpan.org gives you some idea of how active the author is about maintaining the module.

Also, is there a mailing list for the module? Having a mailing list is a pretty good sign of a good-quality, maintained, stable, documented and popular module.

Author:

  • What is the name of the module author?
  • How many other modules has the author released?
  • What kind of modules has the author released?

The author is a big factor. There are some authors who create things which have excellent quality, like Gisle Aas, Graham Barr, Andy Wardley, or Jan DuBois, and some people who turn out a lot of things which could be described as "experimental", like Damian Conway or Tatsuhiko Miyagawa. Be wary of people who've released a lot of Acme:: (joke) modules. Also, beware of things written by people who only maintain one or two modules. People who have fewer than five modules in total usually don't maintain them.

Other things:

cpanratings.perl.org is often helpful, but take it with a grain of salt.

Apart from that, a lot of it is just trial and error. Download and see if it passes its own tests, see if it even has any tests, write a test script, etc.

Things which often don't give a meaningful ranking:

  • The top results on Google tend to be ancient Perlmonks or perl.com or Dr. Dobbs' Journal articles, and these often point you towards outdated things.
  • search.cpan.org's search function puts modules which haven't been updated for ten years on page one, and the latest and greatest on page ten or something.

Beware of "hype":

One more thing I want to say: Be wary of advice on blogs, stackoverflow, Usenet news, etc. - people tend to guide you to whatever module happens to be flavour of the month, rather than a stable, proven solution. The "trendy" modules usually lack documentation, are unstable, have nightmarish dependencies, and quite often yesterday's fashionable modules suddenly fall out of favour and are abandoned, to be replaced by another flavour of the month, leaving you in the lurch if you decide to use them.


Task::Kensho generally makes good recommendations. For sending email it suggests Email::Sender


I'll throw in Email::Stuff. It's a nice wrapper for Email::MIME. You don't need to care about the MIME structure of the mail, the module does it for you.

Email::Stuff->from     ('cpan@ali.as'                      )
            ->to       ('santa@northpole.org'              )
            ->bcc      ('bunbun@sluggy.com'                )
            ->text_body($body                              )
            ->attach   (io('dead_bunbun_faked.gif')->all,
                        filename => 'dead_bunbun_proof.gif')
            ->send;

As for selecting modules,


If you don't need more than the basic features, I suggest looking at Mime::Lite.

use MIME::Lite; 
my $msg = new MIME::Lite
From => 'Your friendly neighbourhood spiderman',
To => 'green@goblin.net', 
CC => 'info@nemesis.org',
BCC => 'mj@spidey.info',
'Reply-to' => 'enemies@spidey.info',
Subject => 'Please stop',
Data     => $data; #Email body

die 'Could not send mail' unless ($msg->send);


You can use Email::Send
http://search.cpan.org/dist/Email-Send/lib/Email/Send.pm


What I prefer is

Mail::Sendmail

MIME::Lite

If you require SSL then include

Net::SMTP::SSL

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号