views:

210

answers:

6

I want to send emails using gmail's smtp servers and perl. I am trying to install Email::Send::Gmail, but it is not clear to me what are the steps to install it. It seems that it depends on other modules that I do not have installed.

+2  A: 

Type:

 cpan Email::Send::Gmail

… at the command prompt.

It's probably a good idea to set up local::lib first.

Or see the Perl Foundation Wiki on installing CPAN modules or the same but without root access.

Or see the CPAN guide to installing modules.

David Dorward
This is ActivePerl, so he should try PPM first. Sending mail to Gmail requires some compiled modules, with at least one requiring the third-party OpenSSL library. It's not as easy as you think it is in this case.
brian d foy
+1  A: 

You can probably install it with:

perl -MCPAN -e shell
install Email-Send-Gmail

Hope it helps,

/Klaus

klausbyskov
`cpan` is less to type
Alexandr Ciornii
This is ActivePerl, so he should try PPM first. Sending mail to Gmail requires some compiled modules, with at least one requiring the third-party OpenSSL library. It's not as easy as you think it is in this case.
brian d foy
+6  A: 

This is partially dependent on which distribution of Perl you're using.

ActivePerl includes a utility called PPM (Perl Package Manager) for installing modules. It handles dependency resolution automatically. PPM is particularly nice for installing XS modules on Windows where a compiler isn't typically available. The downside to PPM is that it some CPAN modules aren't available (probably because they fail ActiveState's automated build process). You can run PPM from either the start menu or by typing ppm at a command prompt.

A more general option is to use the interactive CPAN shell. Note that you must have a compiler to install XS modules using this method. You can access the cpan shell by typing cpan at a command prompt.

The brute-force approach of last resort is to download tarballs from CPAN and manually install them one at a time. When an install aborts due to unsatisfied dependencies download and install them then go back to the first module and try again.

Michael Carman
+1  A: 

If you can, CPAN. (ha! It rhymes ... what a crime. Oops, did it again! When will this end... :p) It's essentially the way to install modules for your system. It automatically detects dependencies, downloads, installs, and tests them all for you, and backs out if ever a build or test fails. It's a fantastic and reliable way of installing modules. This works great if you're using essentially any Perl distribution besides ActiveState's distribution, including Strawberry Perl. Generally, this is done with

cpan Module::Name

or, in an interactive mode,

$ cpan
cpan > install Module::Name

If you're using ActiveState Perl, then you probably want to use ActiveState's PPM (Perl Package Manager). It's similar to CPAN, except everything comes prebuilt for ActiveState Perl. ActiveState has a document on how to use their Perl Package Manager on their website, including a graphical example.

If the easy options fail, you are not out of luck. There's some more complex, but manual methods you can do to still install the module.

Most modules that you can download will have within them a bit of metadata in a .yaml file; this will help you figure out whether or not you have all your dependencies. CPAN and PPM automatically resolve and install all your dependencies, but doing it manually will not, leaving that task up to you.

Assuming you have all your dependencies, and you need to install it manually, look for one of two files: Makefile.PL or Build.PL. If you have a Makefile.PL, cd to the directory you extraced the module within a command prompt, and type:

perl Makefile.PL
make
make test
make install

You will need a 'make' program on your system. If it's ActiveState Perl, you may need to install the module manually (see a paragraph or two down.)

If it happens to have a Build.PL, then you need to do a slightly different set of steps:

perl Build.PL
Build
Build test
Build install

(Of course, you may want to consider not installing if make/Build test fails, but that's up to you.)

As a final alternative, if your module has no xs files (ie, code that needs to be compiled on install), and all dependencies are met, you can simply move the files in the lib folder to your perl installation's site\lib folder. If you're interested in just using it for one project, you can add a PERL5LIB environmental variable, pointing to a new, custom library directory (eg, /my/project/lib) and then before running your tool, make sure the environment is set up.

As a followup, see PerlFaq8 - How do I install a module from CPAN.

Also, see PerlFaq8 - How do I keep my own module/library directory?.

Robert P
You spend the bulk of your answer showing the very hard and difficult way, and give no examples for the right ways.
brian d foy
Fair enough; added some examples and elaborated that the 'rest' of the answer is the emergency/backup ways of getting it working.
Robert P
Most of this particular problem is going to be with OpenSSL issues. PPM is really the preferred method here.
brian d foy
Well, yeah, if it's only ActiveState. This answer made more sense when the question was about installing packages in general, before you changed the title to reflect ActiveState only...
Robert P
I only changed the title based on additional information from the OP. Still, there's more to it even without ActivePerl, as I note in my answer.
brian d foy
+3  A: 

If you are using ActivePerl, try the PPM (Perl Package Manager) tool that comes with ActivePerl first. When you tell it to install a module, it should handle all of the dependencies for you.

Note the dependency tree for Email::Send::Gmail. Some of those modules require additional installation of third party software, most notably OpenSSL, which cpan won't do for you.

brian d foy
+1  A: 

Mixing installation methods is asking for heartache and headaches you don't need.

Don't use CPAN with Active Perl. Use PPM.*

PPM download sources can be found at Randy Kobes' site.

If you can't find a PPM of a module you need, you can build your own PPMs easily with Mr. Kobes make_ppm.

You can download a distribution and simply run make_ppm to build a PPM, but I prefer to do the a more "normal" build process:

perl Makefile.PL
make
make test
make_ppm

*If you install your files outside of c:/perl/site/* then it's OK to use CPAN. Just don't co-mingle CPAN shell modules with PPM modules.

daotoad
Do you have any rationale for not mixing installation methods? I can see it messing up PPM/cpan's idea of what's installed, but it shouldn't cause any problems with the operation of Perl itself. Sometimes modules aren't available via PPM and you have to fall back on cpan or manual installation.
Michael Carman
@Michael, The worst problems I have seen come from mixing RPM and CPAN--that is pure, sweet hell. PPM+CPAN is tame by comparison. The main issue comes in when handling dependency checking. PPM may install a new (or old) version of a module over an existing CPAN module install. This happened to me a couple years ago, things may be better now. This experience was the last straw, and I decided to never mix package managers again. Most things I need are available already packaged. But for the rest PPM::Make is easy to use. I haven't regretted my decision.
daotoad