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

Re: [MacPerl] sendmail? Any Examples?



At 3:26 PM -0700 on 6/9/97, Susan Piepho wrote:

> > At 2.55 97/6/9, Kevin Furuta wrote:
> > >I need to have my script send an email response, using Macperl, but I
> > >cannot seem to find a way that DOES NOT go through the sendmail command.
>
> I would like to see an example of a MacPerl script which will take input
> from a HTML form and send the parsed contents on to a particular Email
> address.

> I understand I should be able to do what I want with libnet and the
> associated programs....

> However, to know how to use these packages with MacPerl to do what I
> want, I really need to see some good examples.

Well, the following quick hack won't replace your sendmail command, but
it'll get close.  This is more like the Unix mconnect where you have to
send SMTP commands to a mailserver.  It uses the SMTP.pm module from the
libnet distribution (which, as you recall, requires Data Dumper).  My
module has only been slightly modified from the documentation from the one
included with the SMTP.pm module.

You'll want to modify a few of the variables. :)  I've tested this only as
a CGI script.  (The CGI script will be served better with hashes, but this
was a quick hack.  I'm almost embarassed to distribute this. :)

In your script:

	require(Mconnect);
	#set the appropriate variables
	$from = "cgi-script\@louie.net";
	$to = "louie\@louie.net";
	$subject = "Test subject";
	$body = "This is a test of the body.";
	#send the message
	&mconnect("$from","$to","$subject","$body");

Then your module can read:

	#Mconnect.pm
	sub mconnect.pl {
		my($from, $to, $subject, $body);
		use Net::SMTP;

		$smtphost = "louie.net";	# SMTP server
		$hello = "louie.net";		# localhost
		$timeout = "30";		# server connection timeout

		$smtp = Net::SMTP->new("$smtphost",
                	               Hello => "$hello",
                	               Timeout => $timeout
                	               );

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

		$smtp->data();
		$smtp->datasend("From: $from\n") if $from ne "";
		$smtp->datasend("To: $to\n");
		$smtp->datasend("Subject: $subject\n") if $subject ne "";
		$smtp->datasend("\n$body\n");
		$smtp->dataend();

		$smtp->quit;
	}
	1;

Good luck,
Louie



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