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

I have ActivePerl 5 and it is installed on an NT system. I'm working on an intranet site for my company and need to use cgi to email user input in a parsed format to my boss or whoever... Most tutorials mention SENDMAIL, a unix program that takes care of this, but the perl is on a Win32 system... What's the best way to do this? I looked on other tutorials but they mention libraries that I cannot seem to find in my installation of Perl... is there some place to get them? *ie NET::SMTP etc...
  • Comment on Perl in Win32: How do I email form output?

Replies are listed 'Best First'.
Re: Perl in Win32: How do I email form output?
by Mungbeans (Pilgrim) on May 24, 2001 at 18:52 UTC
    You can get the packages from: http://www.activestate.com/ppmpackages/

    Bookmark this it can be hard to find.

    Net::SMTP will do the job... this below provides a basic wrapper for some admin scripts I use. N.B. recipient list would be better as an array reference.

    sub send_mail_via_smtp() { ### Parameters my ($smtp_server, $recipient_list, $from, $subject, $body) = @_; ### Locals my $to_line = ''; my $smtp = ''; my @recipients = ''; my $recipient = ''; ### connect to SMTP server $smtp = Net::SMTP->new( $smtp_server, #Debug => 1, ) or die "send_mail_via_smtp(): Unable to connect to $smtp_server, +$!, Stopped"; $smtp->mail($from); @recipients = split(/,/, $recipient_list); foreach $recipient (@recipients) { $smtp->to($recipient); $to_line = $recipient . ',' . $to_line } $to_line =~ s/,$//; # Strip off any trailing ,'s ### Start the actual mail $smtp->data(); ### Header $smtp->datasend("To: $to_line\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: $subject:\n"); $smtp->datasend("\n"); ### Body $smtp->datasend("$body\n"); ### Send $smtp->dataend(); $smtp->quit; }
Re: Perl in Win32: How do I email form output?
by Beatnik (Parson) on May 24, 2001 at 18:59 UTC
    Might as well mention the Net::SMTP URL, as well as NT Sendmail, the actual Sendmail app itself (which is also available on windows), as Blat. Mail::Sender can use several other Mail modules to send mail.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      My installation of perl doesn't even HAVE a mail directory in the lib directory!!!
        Assuming Perl is installed properly :
        1. Read PPM FAQ
        2. Read PPM FAQ
        3. Read PPM FAQ
        4. Read PPM FAQ
        5. Read PPM FAQ
        6. Log in as administrator
        7. Open a DOS box
        8. type : ppm and press enter
        9. type : install Net::SMTP and press enter
        10. follow steps described by PPM

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
Re: Perl in Win32: How do I email form output?
by larryk (Friar) on May 24, 2001 at 19:32 UTC
    #!perl -w use strict; use Win32::OLE; my $message = ''; while (<DATA>) { $message .= $_; } my $mail = new Win32::OLE('Outlook.Application'); my $item = $mail->CreateItem(0); $item->{'To'} = 'email@address.here'; $item->{'Subject'} = 'whatever you want'; $item->{'Body'} = $message; if ( $item->Send() ) { print "email sent.\n" } else { print "email not sent!\n" } __DATA__ blah blah blah
Using ppm (was Re: Perl in Win32: How do I email form output?)
by mrmick (Curate) on May 24, 2001 at 18:42 UTC
    If you have ActivePerl, then you can use ppm to get the modules you need. If there are any problems with getting through a firewall, you can download the packages from Activestate's ftp site and install through ppm as well. The documentation that comes with Activeperl is very clear. Look in the html directory on your Perl installation. (C:\perl\html\index.html, for example).

    Mick
Re: Perl in Win32: How do I email form output?
by strfry() (Monk) on May 24, 2001 at 19:02 UTC
    if you're looking for a program outside perl that sends e-mail, i'd suggest blat.

    (and for a neat overview on using blat, do a search on it here, and maybe google too)
      Blat's an excellent program. I'm running ActivePerl on Win95 (sorry!), and needed to email form output. I used sendmail for Windows for some time, but it expired after thirty days and I switched to blat, which does the job just fine.
Re: Perl in Win32: How do I email form output?
by AidanLee (Chaplain) on May 24, 2001 at 20:35 UTC
    Honestly, I'm a big fan of Mail::Sender. It isn't as low-level as NET::SMTP and can be set up with a minimum of fuss, which is usually desirable in a scenario such as yours.
Re: Perl in Win32: How do I email form output?
by novitiate (Scribe) on May 24, 2001 at 20:19 UTC
    ActiveState includes Graham Barr's libnet libarary, of which Net::SMTP, is a part. To see if you have it, just do:

    perl -e "use Net:SMTP;"

    bumbly,
    novitiate
Re: Perl in Win32: How do I email form output?
by Anonymous Monk on May 24, 2001 at 22:11 UTC
    You could also use the Mail::Sendmail module. It works equally well in both Unix and Win32.
Re: Perl in Win32: How do I email form output?
by mexnix (Pilgrim) on May 24, 2001 at 22:17 UTC
    If you have the ability to spend money on this gig, you might want to look at Sendmail by Indigo Star. I used this at an ISP that I worked at and it did the job. One licencse covers as many instances you want on a single server. Just put the .exe in your cgi-bin dir and it works. Has a small config file and a log file (for each instance). They even have perl examples on the site. Check it out.

    Ryan Briones

Re: Perl in Win32: How do I email form output?
by murphya (Sexton) on May 25, 2001 at 18:15 UTC
    In my experience Mail::SendMail is the way to go. Very easy to set, use and understand. Once you get it working once you can rip off the code for other applications and it is pretty much platform independent.