G
GVDC
Example server-side JavaScript Web script, Pipe class
//sending email using Pipe class and sendmail:
//
printf("<html><body>");
var pipeobj = new Pipe("/usr/sbin/sendmail (e-mail address removed)");
//set errno 0
Server.errno(0);
if ( pipeobj.open()==true ) {
var smsg = ""
+"From: (e-mail address removed)\n"
+"To: (e-mail address removed)\n"
+"Subject: Webscript test email\n"
+"\n"
+"Text text text\n"
+"more text some more text etc.\n"
+"\n"
;
//writing ok
if ( pipeobj.write(smsg)!=(-1) ) {
pipeobj.close(1); //close write end
printf("<pre>");
printf(pipeobj.read()); //read and print output, if any
printf("</pre>");
}
//error
else {
printf("Failed writing to pipe: " , Server.errnstr() ,"<br\n>");
printf("Msg text:<br>" , smsg ,"<br\n>");
}
var xstatus = pipeobj.close(); //final close completely closes pipe and returns pipe status
//if non-zero there was an error or process unclean exit
if ( xstatus!=0 ) {
printf("Closing pipe indicate failure [exit status " , xstatus ,"]<br\n>");
printf("System status: " , Server.errnstr() ,"<br\n>");
}
}
else {
printf("Opening pipe failed, system status: " , Server.errnstr() ,"<br\n>");
}
printf("</body></html>");
--
//sending email using Pipe class and sendmail:
//
printf("<html><body>");
var pipeobj = new Pipe("/usr/sbin/sendmail (e-mail address removed)");
//set errno 0
Server.errno(0);
if ( pipeobj.open()==true ) {
var smsg = ""
+"From: (e-mail address removed)\n"
+"To: (e-mail address removed)\n"
+"Subject: Webscript test email\n"
+"\n"
+"Text text text\n"
+"more text some more text etc.\n"
+"\n"
;
//writing ok
if ( pipeobj.write(smsg)!=(-1) ) {
pipeobj.close(1); //close write end
printf("<pre>");
printf(pipeobj.read()); //read and print output, if any
printf("</pre>");
}
//error
else {
printf("Failed writing to pipe: " , Server.errnstr() ,"<br\n>");
printf("Msg text:<br>" , smsg ,"<br\n>");
}
var xstatus = pipeobj.close(); //final close completely closes pipe and returns pipe status
//if non-zero there was an error or process unclean exit
if ( xstatus!=0 ) {
printf("Closing pipe indicate failure [exit status " , xstatus ,"]<br\n>");
printf("System status: " , Server.errnstr() ,"<br\n>");
}
}
else {
printf("Opening pipe failed, system status: " , Server.errnstr() ,"<br\n>");
}
printf("</body></html>");
--