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

Re: [MacPerl] question 2 of 2 (much shorter)



>Andrew again. I'm back!  muahahaha.
>I have one more question, also only asked after I've fiddled for hours on
>my own.
>Is there an effective way to send mail using MacPerl.  It's easy on UNIX,
>but how do I do it without sendmail?  I've seen a couple of scripts that
>purport to speak SMTP and send mail directly, but I haven't gotten any of
>them to work.
>I did get an AppleScript to send simple SMTP mail, but i don't think I
>can tie that into a MacPerl CGI, can I?
>
>Thanks again!
>andrew
>

This might help you - I have setup a subroutine to mail status messages
from cgi's.
It uses the "Net::SMTP" module (requires MacPerl 5.10), and should run on
Unix Perl5 (but I haven't tested that yet).
You will have to get the "Net" package and add the files to your "lib:Net"
folder for MacPerl.
It's quite simple, you just pass this subroutine a subject and message.  I
read the SMTP host, "to" and "from" data from a preconfigured associative
array.

I hope this helps...


sub mailStatus {
        use Net::SMTP;
        local ($subject,$message) = @_;
        local ($mailhost) = $config{"SMTP"};
        local ($to) = $config{"adminmail"};
        $from = $config{"fromAddr"};

        $smtp = Net::SMTP->new($mailhost);

        $smtp->mail($from);
        $smtp->to($to);

        $smtp->data();
        $smtp->datasend("Subject: $subject\n\n");

        $smtp->datasend($message);
        $smtp->dataend();

        $smtp->quit;
}


John Kirkham
Global-X-Change Communications Inc.
Sys. Admin./Tech. Support/ Programmer
Ottawa, Ontario, Canada
jkirkham@globalx.com
http://www.globalx.net