[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Email & CGIs



'lo all,

  I have been struggling with trying to get MacPerl CGIs to send email for
a while now.  I thought I'd share what I know in case it helps anyone. 

  The best and most flexible way to send email that I've found has been to
use the MailTools library.  The only problem is that it isn't included
with the MacPerl distribution so you have to download and install it
yourself.

  The latest version of MailTools can be found at
<http://www.perl.com/CPAN-local//modules/by-module/Mail/>.  (As of this
writing the latest version is 1.12 and the file you want to get is
MailTools-1.12.tar.gz.)  After you download this file, you have to decode
it.  If you have StuffIt Expander _and_ DropStuff With Expander Enhancer
installed, you can just drag and drop the file on your StuffIt Expander
icon and you will end up with a MailTools folder.  (Any other program that
can decode Gzip and tar files will work just as well.)

  If you don't already have a folder in your MacPerl folder called
"site_perl", create one now.  Then take the "Mail" folder from the
MailTools folder and put it in your "site_perl" folder.

  Now you want to convert all the files in the Mail folder so that they
have Mac-style line breaks.  The easiest and quickest way that I've found
is to use the lf2cr4mac.dp droplet that's on the CD that comes with
MacPerl: Power and Ease.  You can just select all the files in a folder,
drag and drop them on the droplet, and then trash the original files.
If you haven't bought MacPerl: Power and Ease yet (shame on you...), you
can also convert files using most text editors.

  Now comes a slightly trickier part.  In order for the libraries to work
correctly, some files have to be split into separate parts.  This is a
one-time task that a simple Perl script can easily handle.  In version
1.12 of MailTools, the only files that need to be split are Internet.pm
and Util.pm so the following script works fine.  This script may need to
be adjusted for future versions.

    #!perl -w
    use AutoSplit;
    my $dir = "$ENV{MACPERL}site_perl";
    autosplit("$dir:Mail:Internet.pm", "$dir:auto", 0, 1, 1);
    autosplit("$dir:Mail:Util.pm", "$dir:auto", 0, 1, 1);

  The MailTools library should be ready to go!  The only other adjustment
you may have to make is to make sure that your SMTP Host is set correctly 
in Internet Config since MailTools on the Mac uses SMTP to send mail.

  Here is a simple sample script that shows how MailTools works.

    use Mail::Mailer;

    $from_address = 'me@myhost.com';
    $to_address = 'you@yourhost.com';
    $subject = "MacPerl and MailTools";
    $body = <<END_OF_BODY;
    This email message is being sent by MacPerl.
    MacPerl is using the MailTools libraries to send it.
    Pretty cool, huh?
    END_OF_BODY

    $mailer = Mail::Mailer->new();
    $mailer->open({ From    => $from_address,
                    To      => $to_address,
                    Subject => $subject,
                  })
        or die "Can't open: $!\n";
    print $mailer $body;
    $mailer->close();

  Much of what I have written here is based off of
<http://www.perl.com/CPAN-local//modules/INSTALL.html>, MacPerl: Power and
Ease by Vicki Brown and Chris Nandor, and the MailTools man pages.  I am
just customizing it for use with the MailTools package.  Also, I am no
expert.  Use my advice at your own risk.  Any corrections, clarifications,
and/or additions are welcome and encouraged.

  Thanks.

-- 
===========================================================================
Andy Berkvam          | A man said to the Universe: "Sir, I exist!"
                      | "However," replied the Universe, "the fact 
Email:                |  has not created in me a sense of obligation."
 aberkvam@coredcs.com |                                     - Stephen Crane
 (MIME Attachments OK)|-WWW Pages: <http://www.coredcs.com/~aberkvam/>
===========================================================================




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch