Stoney has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, New here and this is my first post so please answer as though I don't talk 'Monkish' :) Is it possible to send mail using Perl when the host's server doesn't have (and won't install) any modules. They suggested I use 'formmail' by BrainJar in .asp which works fine but I'd rather use Perl... Many thanks in advance. Sarah

Replies are listed 'Best First'.
Re: sending mail without modules?
by massa (Hermit) on Jan 29, 2009 at 13:49 UTC
    First of all, Net::SMTP is a core module, that should be installed whenever perl is installed. That said, your solution seems to be something like:
    #!/usr/bin/perl use strict; use warnings; use Net::SMTP; my $smtp = Net::SMTP->new( Host => 'mailhost.from.com', Hello => 'thishost.from.com' ); $smtp->mail('from@from.com'); $smtp->to('to@to.com'); $smtp->data('this is the text of the message'); $smtp->quit;
    []s, HTH, Massa (κς,πμ,πλ)
Re: sending mail without modules?
by zentara (Cardinal) on Jan 29, 2009 at 13:31 UTC
    This is the old way of accessing your sendmail program directly. It is generally frowned upon by Perler's, but it usually works. (on win32 your mail program may be called "blas", IIRC
    #!/usr/bin/perl use warnings; use strict; my $mailprog ="/usr/sbin/sendmail"; my $mailflags ="-t -n -oi"; my $recipient = 'recipient@domain.com'; my $msg_goes_here = "you're message"; open SENDMAIL, "| $mailprog $mailflags" or warn $!; print SENDMAIL "From: user\@domain.com\n"; print SENDMAIL "To: $recipient\n"; print SENDMAIL "Subject: testing 123\n\n"; print SENDMAIL $msg_goes_here; close SENDMAIL;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: sending mail without modules?
by Anonymous Monk on Jan 29, 2009 at 13:59 UTC
Re: sending mail without modules?
by scorpio17 (Canon) on Jan 29, 2009 at 14:24 UTC
    Assuming you have a shell login to your host, you can always install modules locally - in fact, this is usually a better way to go in any event, because then you can control which version you're using, when to upgrade, etc. And if you switch hosts, just tar up your perl directory and ftp it - you're guaranteed to have the same stuff at the new host. Read the docs for the CPAN module, and check the FAQs on this site for installing locally.
As good as Solved Re: sending mail without modules?
by Stoney (Novice) on Jan 31, 2009 at 09:06 UTC
    Many thanks for all the replies, they're all really helpful. I haven't solved it yet as I need to look into the various suggestions of how to solve it and which would be most suitable for this situation, and that may take me some time. Sarah