SndMsg console utility to send mail message

|smallsrv.com| |Description| |Get sndmsg.exe| |Soft| |Forum| |License|


Often incompotible between scripts under Unix and under Windows is the absence of "sendmail" program and sometimes the absence of "popen" function. It's easy to decide this problem under Small HTTP server. Just enable SMTP server, option it, and create files with messages in OUTBOX directory. The name of this files must be generated by next format "%8.8X.msg" First line of this file must have next format:
From return@address (from_server [##.##.##.##]) Date For destination@address
e.g.
From myscript@host.com (via Web [127.0.0.1]) Wed, 9 Jan 2002 21:16:46 GMT For admin@host.com
If "popen" function is avilable in your script, or open with "|" mode in Perl you can use easy Sendmail emulator (download 11 Kb). This program must be placed in directory upper then OUTBOX or you must use key "-o" to direct OUTBOX location. (In server's options SMTP must be enabled, and full path for OUTBOX is hard recomended, to send messages immediatle) Command line:
sndmsg {Keys} [to@address]
Next keys are supported:
-t  -- read recipients from message
-o d:\outbox\foulder  -- OUTBOX subderectory in Small HTTP server
-o smtp://smtp.address[:25] -- Out to SMTP server
-f from@address
-F full name
-s  -- save From lines in headers
-m filename  -- message file instead stdin
-a filename  -- attach binary file

Other keys are ignored.
to@address or key -t must be.
You can write your own replacement of sendmail. Here is an example on C of function that replace popen("/usr/bin/sendmail to@address","w"):

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

const char outbox[]="..\\..\\outbox"; // Here you must direct your path to OUTBOX.


FILE * sendmail(char *from,char *to)
{
 char bfr[512];
 int  t;
 FILE *r;
 struct stat st;

 t=time();
 do{          // find uniq file name.
  sprintf(bfr,"%s\\%8.8X.msg",outbox,--t);
 }while( stat(bfr,&st)!=-1 )
 r=fopen(bfr,"w");
 fprintf(r,"From %s (via Web [%s]) %s For %s\n",
         from, getenv("REMOTE_ADDR"), getenv("DATE_GMT"), to);
 return r;
};