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

[MacPerl-WebCGI] Re: The SendMail thing



on 2000-02-09, David Reynolds wrote:
>Good luck finding a way to do that.  I'd like to know if you get an answer.

I've attached a script that I use, it's a bit long so I put it at the end...

>I'd also like to know how to limit the size of files with an http upload,
>but I guess thats just asking way too much.

If you use perl, it can be done like this:

########
	$filename = $query->param('uploaded_file');
	$type = $query->uploadInfo($filename)->{'Content-Type'};

#
#	snippet som stuff about using $type to build a sane filename,
#	setting up $fil etc.
#

	open (OUTFILE,">>$fil");
         while ($bytesread=read($filename,$buffer,1024)) {
	    $size += $bytesread;
	    if ($size > $maxsize) {
		$dele = 1;
	    	last;
	    }
             print OUTFILE $buffer;
         }
	unlink $fil if $dele;
########


and the mail sending stuff:
#############################
#!/usr/local/bin/perl -w
# quick-n-dirty mail sending script
#
# chr@solvare.se
#

use Net::SMTP;

#
#	snippet setting up variables...
#	Sorry for the Swedish names...
#
#	$mig is the sender's e-mail
#	$mott is the recipient
#	$subj is the subject of the message
#	$body is the body of the message
#	$mailhost is a friendly smtp server
#

@body = split(/\n/,$body);

my ($jag, $mailhost) = split("\@",$mig);

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

$smtp->mail($mig);

$smtp->to($mott);

$smtp->data();
$smtp->datasend("Content-Transfer-Encoding: iso-8859-1\n");
$smtp->datasend("Content-Type: text/plain; charset=\"iso-8859-1\"\n");
$smtp->datasend("Subject: $subj\n");

$smtp->datasend("\n");

while (@body){
   $text = shift @body;
   $smtp->datasend("$text\n");
}

$smtp->dataend();

$smtp->quit;

# done
# - hopefully, there's no error checking...
######################################

Christian

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org