#!/usr/bin/perl -w # The first line of the file is unnecessary for the Novonyx servers, but is necessary for other # web servers, leave it in to keep the code portable. ################################ # Necessary Fields in HTML Form: # SendersDepartment = specifies the remote users department # sendername = specifies the remote users real identity # subject = the subject line that will appear in your email # link1 = the url for the link, relative to your web entry point # (ie link1="/index.html") # link2 = the text that will be printed for the link back on the return html page # (ie link2="Back to Wild Things Photography Home") # The first thing that must be printed out to a web page is the following line. It doesn't # actually print, but it tells the web server what format you will be sending it from this # program print "Content-type: text/html\n\n"; # Sendmail is saved as a separate program, so in order to use it, it must be "required" require("sendmail.pl"); # If the requestMethod is "POST", the data will be read from STDIN, # if "GET" it will be read from the URL line $requestMethod = $ENV{"REQUEST_METHOD"}; $input = ""; if($requestMethod eq "POST") { read(STDIN, $input, $ENV{"CONTENT_LENGTH"}); } else { $input = $ENV{'QUERY_STRING'}; } # Strip off white space and any html tags that come in with the form data, and # create an array of the name/value pairs %in = UnencodeFormData(); sendmail(%in); # Print Return HTML # Any reference to graphics of other URLs need the path relative to your web entry point # If your entry point is sys:/novonyx/suitespot/docs and your graphics are in # ~docs/web/graphics # the url to use is /web/codebreak/graphics/image.jpg print "
\n";
print " \n";
print "Thank you for your email\. \n"; print "To continue from where you left off simply click the button below. \n"; print " \n"; print " | |
$ITEM{link2} |
The following code is from the sendmail.pl file
#!/usr/bin/perl -w
use Socket;
use strict;
sub sendmail()
{
my (%body) = @_;
my $line = "";
# Substitute your mail server here.
my($mailServer) = 'mailhub.health.nb.ca';
#These next fields come in from the form, your form should have at least the following
# fields: To, SendersDepartment, Sender, subject
my($mailTo) = "$body{To}\n\n\n\n";
my($mailFrom) = "$body{SendersDepartment}";
my($realName) = "$body{Sender}";
my($subject) = "$body{subject}";
# These constants shouldn't need changing.
my($packFormat) = 'S n a4 x8'; #Internet address format (AF_INET:portNumber:serverAddress:eightNulls)
my($proto) = getprotobyname("tcp") || 6;
my($port) = getservbyname("SMTP", "tcp") || 25;
my($name,$aliases,$addrtype,$len,@addrs) = gethostbyname($mailServer);
my($serverAddr) = $addrs[0];
# If this script dies at this line, it is because you don't have an entry in the SYS:\etc\hosts
# file for your mail server. Manually add an entry for the mail server if not already there.
if (! defined($len)) {
die('gethostbyname failed.');
}
socket(SMTP, AF_INET(), SOCK_STREAM(), $proto)
or die("socket: $!");
connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr))
or die("connect: $!");
select(SMTP); $| = 1; select(STDOUT); # use unbuffered i/o.
{
my($inpBuf) = '';
recv(SMTP, $inpBuf, 200, 0);
}
sendSMTP(1, "HELO\n");
sendSMTP(1, "MAIL FROM: <$mailFrom>\n");
sendSMTP(1, "RCPT TO: <$mailTo>\n");
sendSMTP(1, "VRFY\n");
sendSMTP(1, "DATA\n");
sendSMTPnoresponse(1, "From: $realName <$mailFrom>\n");
sendSMTPnoresponse(1, "Subject: $subject\n");
sendSMTPnoresponse(1, "\n");
# Print each of the name/value pairs coming from the form IF they have been filled in
for $line (keys %body)
{
if($line !~ /link/ && $line !~ /subject/) # We don't need to print out the hidden form fields
{
sendSMTPnoresponse(1, "$line = $body{$line}\n") if($body{$line});
}
}
# Since we have put the name/value pairs into a hash which stores randomly, using the above
# for loop will print the name/value pairs randomly in your email message.
# To print them in a specific sequence, you can explicitly print each one with the following
# format (INSTEAD OF using the for loop).
# sendSMTPnoresponse(1, "Sender\'s Name = $body{Sender}\n") if($body{Sender});
# sendSMTPnoresponse(1, "Sender\'s Department = $body{SendersDepartment}\n") if($body{SendersDelpartment});
# sendSMTPnoresponse(1, "Message = $body{Message}\n") if($body{Message});
sendSMTPnoresponse(1, "\n");
sendSMTP(1, ".\n");
sendSMTP(1, "QUIT\n");
close(SMTP);
}
sub closeSocket { # close smtp socket on error
close(SMTP);
die("SMTP socket closed due to SIGINT\n");
}
sub send_to_smtp {
my($debug) = shift;
my($response) = shift;
my($buffer) = @_;
# Uncomment the following line for debugging only
# print STDERR ("> $buffer") if $debug;
send(SMTP, $buffer, 0);
if ($response) {
recv(SMTP, $buffer, 200, 0);
# Uncomment the following line for debugging only
# print STDERR ("< $buffer") if $debug;
return( (split(/ /, $buffer))[0] );
}
}
sub sendSMTP {
my ($debug) = shift;
send_to_smtp($debug, 1, @_);
}
sub sendSMTPnoresponse {
my ($debug) = shift;
send_to_smtp($debug, 0, @_);
}
1; #return true