Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email from acucobol 1

Status
Not open for further replies.

fdf

MIS
Jul 30, 2003
38
US
I need to email forms (po's, statements, etc) from an acucobol (character) application on an SCO unix server. Need an operating program with available source, preferably acucobol, but could be a windows language (vb, etc). I'm open to using sendmail or a microsoft interface. Also interested in potential application of graphic overlays.

Have budget.
 
Si te sirve un programa en C, es el que yo uso desde mi aplicacion en acucobol tanto en sco como en linux.

Este programa manda por correo un fichero de texto cuyo nombre se lo pasas en la linea de comandos. Es decir el fichero tiene que estar ya creado, tiene que ser de tipo texto y si quieres que en el mail aparezca el subjet, debe comenzar con la linea
subject: lo que sea.

POr tanto no funciona para mandar attachs ni binarios, etc, solo fichero de texto puro y duro.


Tienes que hacer un call "system" using linea-comando.
La linea-comando sera un nivel 01 o 77 de la working con el valor
01 linea-comando.
03 pic x() value "mandomail [y todas las opciones]".

Las opciones, las tienes explicadas en el programa fuente, al comienzo. Tambien tienes que tener declaradas y exportadas las variables MIMAIL y MISMTP con la direccion del remite y la direccion del servidor SMTP que vayas a usar.

El sistema SCO tiene que tener las rutas de salida a internet definidas en el fichero /etc/resolv.conf, asi como los DNS que uses.

Espero que te valga.

Saludos.

/*
llamada al programa:
enviomail -r remite -d destino -f fichero -c llcc -v -l fichero -x color
el origen lo tomo de la variable MIMAIL
el servidor lo tomo de la variable MISMTP
cuando uso la opcion -v, llcc es la linea y posicion del cursor donde
saco los mensajes, (siempre cuatro cifras como el at de cobol)
por defecto linea 24 y posicion 1 si no se dice nada
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#define PORTNUM 25
int fondos[9]={40,40,44,42,46,41,42,43,47};
int textos[9]={30,30,34,32,36,31,35,33,37};
static FILE *sfp;
static FILE *rfp;
static FILE *datos;
static FILE *fplog;
int que_color=44;
int lin=24;
int pos=1;
char mismtp[50];
char mimail[50];
char destino[50];
char fichero[50];
char filelog[50];
char textosvarios[50];
char my_name[BUFSIZ];
int s;
int get_response(void);
int tiempo_maximo=20;
int nivellog=0; /* 0=nada, 1=sacar resumen 2=salida standar 3=fichero */

void byebye(senal)
int senal;
{
mensaje_operador(&quot;EL SERVIDOR NO RESPONDE&quot;, &quot;TIMEOUT&quot;);
exit(253);
}
main(argc, argv)
int argc;
char *argv[];
{
int status;
char buf[BUFSIZ];
memset(mismtp, 0, sizeof(mismtp));
memset(mimail, 0, sizeof(mimail));
memset(destino, 0, sizeof(destino));
memset(fichero, 0, sizeof(fichero));
memset(filelog, 0, sizeof(fichero));
if (argc==1)
{
usage(argc, argv);
exit(254);
}
captura_datos(argc, argv);
if(nivellog > 1)
muestra_datos();

alarm(tiempo_maximo);
signal(SIGALRM, byebye);
inicializa();
alarm(0);
/*leo el saludo inicial*/
if( get_response() == 0)
{
exit(21);
}

/*saludo al servidor de correo*/
mensaje_operador(&quot;ENVIANDO CORREO&quot;, &quot;ENVIANDO CORREO&quot;);
if(nivellog>1)
{
sprintf(textosvarios, &quot;HELO %s&quot;, my_name);
mensaje_operador(textosvarios, textosvarios);
}
fprintf(sfp, &quot;HELO %s\r\n&quot;, my_name);
fflush(sfp);
if( get_response() == 0)
{
exit(21);
}


if(nivellog>1)
{
sprintf(textosvarios, &quot;MAIL FROM: %s&quot;, mimail);
mensaje_operador(textosvarios, textosvarios);
}
fprintf(sfp, &quot;MAIL FROM: %s\r\n&quot;, mimail);
fflush(sfp);
if( get_response() == 0)
{
exit(22);
}
if(nivellog>1)
{
sprintf(textosvarios, &quot;RCPT %s&quot;, destino);
mensaje_operador(textosvarios, textosvarios);
}
fprintf(sfp, &quot;RCPT TO: %s\r\n&quot;, destino);
fflush(sfp);
if( get_response() == 0)
{
exit(22);
}

if(nivellog>1)
{
sprintf(textosvarios, &quot;ENVIANDO DATOS&quot;);
mensaje_operador(textosvarios, textosvarios);
}
fprintf(sfp, &quot;DATA\r\n&quot;);
fflush(sfp);
if( get_response() == 0)
{
exit(22);
}
alarm(tiempo_maximo);
memset(buf, 0, sizeof(buf));
while (fgets(buf, sizeof(buf), datos))
{
buf[strlen(buf)-1] = 0;
if (strcmp(buf, &quot;.&quot;) == 0) /*la linea solo tiene un punto ?? */
{
fprintf(sfp, &quot;..\r\n&quot;); /*meto dos puntos*/
fflush(sfp);
}
else
{
fprintf(sfp, &quot;%s\r\n&quot;, buf);
fflush(sfp);
}
memset(buf, 0, sizeof(buf));
}

fprintf(sfp, &quot;.\r\n&quot;);
fflush(sfp);

if( get_response() == 0)
{
exit(22);
}

mensaje_operador(&quot;FIN ENVIO&quot;, &quot;FIN ENVIO&quot;);

if(nivellog>1)
{
sprintf(textosvarios, &quot;QUIT&quot;);
mensaje_operador(textosvarios, textosvarios);
}
fprintf(sfp, &quot;QUIT\r\n&quot;);
fflush(sfp);
fclose(sfp);
fclose(datos);
if (nivellog>2)
fclose(fplog);

} /*de main*/

int get_response(void)
{
char buf[BUFSIZ];
while (fgets(buf, sizeof(buf), rfp))
{
buf[strlen(buf)-1] = 0;
if(nivellog >1 )
mensaje_operador(buf, buf);
if (!isdigit(buf[0]) || buf[0] > '3')
{
mensaje_operador(&quot;ERROR EN SMTP&quot;, &quot;EL SERVIDOR DIO ERROR&quot;);
return 0;
}
if (buf[4] != '-')
break;
}
return 1;
}
inicializa()
{
int r;
struct sockaddr_in sin;
struct hostent *hp;
mensaje_operador(&quot;CONECTANDO CON EL SERVIDOR&quot;, &quot;CONECTANDO CON EL SERVIDOR&quot;);
if (gethostname(my_name, sizeof(my_name) - 1) < 0)
{
mensaje_operador(&quot;ERROR:11&quot;, &quot;FALLO GETHOSTNAME&quot;);
exit(11);
}
hp=gethostbyname(mismtp);
if (hp==NULL)
{
mensaje_operador(&quot;ERROR:12&quot;, &quot;FALLO GETHOSTBYNAME&quot;);
exit(12);
}

if (hp->h_addrtype != AF_INET)
{
mensaje_operador(&quot;ERROR:13&quot;, &quot;FALLO ADDRESS FAMILY&quot;);
exit(13);
}
memset((char *)&sin, 0, sizeof(sin));
memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
sin.sin_family = hp->h_addrtype;
sin.sin_port = htons(PORTNUM);
if((s=socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
mensaje_operador(&quot;EL SERVIDOR NO RESPONDE&quot;, &quot;FALLO SOCKET&quot;);
exit(14);
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
{
mensaje_operador(&quot;EL SERVIDOR NO RESPONDE&quot;, &quot;FALLO CONNECT&quot;);
exit(15);
}

if ((r = dup(s)) < 0)
{

mensaje_operador(&quot;ERROR 16&quot;, &quot;FALLO DUP&quot;);
exit(16);
}
if ((sfp = fdopen(s, &quot;w&quot;)) == 0)
{
mensaje_operador(&quot;ERROR 17&quot;, &quot;FALLO FDOPEN 1&quot;);
exit(17);
}
if ((rfp = fdopen(r, &quot;r&quot;)) == 0)
{
mensaje_operador(&quot;ERROR 18&quot;, &quot;FALLO FDOPEN 2&quot;);
exit(18);
}
}
usage(argc, argv)
int argc;
char *argv[];
{
printf(&quot;usar %s -d destino -f fichero -v -l filelog -c llpp\n &quot;, argv[0]);
printf(&quot;-t time.max -r remite -x color \n&quot;);
puts(&quot;estando definida como variable de entorno MISMTP&quot;);
puts(&quot;MISMTP es el servidor de correo al que nos conectamos&quot;);
puts(&quot;se puede usar MIMAIL como mi direccion de correo en vez de -r &quot;);
puts(&quot;llpp es la linea y posicion cuando usamos la opcion v&quot;);
puts(&quot;deben ser con cuatro digitos como el at de cobol&quot;);
exit(1);
}
captura_datos(argc, argv)
int argc;
char *argv[];
{
int k;
int haydestino=0, hayfichero=0, hayremite=0;
char *puntero;
while((k=getopt(argc, argv, &quot;x:d:r:f:l:c:t:v&quot;)) != -1)
{
switch(k)
{
case 'd' : strcpy(destino, optarg);
haydestino++;
break;
case 'r' : strcpy(mimail, optarg);
hayremite++;
break;
case 't' : tiempo_maximo=atoi(optarg);
break;
case 'x' : que_color=atoi(optarg);
break;
case 'f' : strcpy(fichero, optarg);
hayfichero++;
break;
case 'c' : lin=((optarg[0] - '0') * 10 ) + (optarg[1] - '0');
pos=((optarg[2] - '0') * 10 ) + (optarg[3] - '0');
break;
case 'v' : if(nivellog==0)
{
nivellog=1;
}
break;
case 'l' : strcpy(filelog, optarg);
if (filelog[0] == '-')
{
nivellog=2;
}
else
{
if ((fplog = fopen(filelog, &quot;w+&quot;)) == 0)
{
puts(&quot;NO PUEDO ABRIR FICHERO LOG&quot;);
exit(3);
}
nivellog=3;
}
break;
}
}
if (hayremite==0)
{
puntero=getenv(&quot;MIMAIL&quot;);
if (puntero != NULL)
{
strcpy(mimail, puntero);
}
else
{
mensaje_operador(&quot;ERROR1&quot;, &quot;DEBE ESTAR DEFINIDA VARIABE MIMAIL&quot;);
exit(1);
}
}
puntero=getenv(&quot;MISMTP&quot;);
if (puntero != NULL)
{
strcpy(mismtp, puntero);
}
else
{
mensaje_operador(&quot;ERROR2&quot;, &quot;DEBE ESTAR DEFINIDA VARIABE MISMTP&quot;);
exit(2);
}
if(haydestino==0)
{
mensaje_operador(&quot;FALTA DESTINO&quot;, &quot;NO SE A QUIEN TENGO QUE ENVIAR&quot;);
exit(4);
}
if(hayfichero==0)
{
mensaje_operador(&quot;FALTA FICHERO&quot;, &quot;NO SE QUE FICHERO TENGO QUE ENVIAR&quot;);
exit(5);
}
if ((datos = fopen(fichero, &quot;r&quot;)) == 0)
{
mensaje_operador(&quot;FICHERO NO ENCONTRADO&quot;, &quot;FICHERO NO ENCONTRADO&quot; );
exit(6);
}

}
muestra_datos()
{
sprintf(textosvarios, &quot;direccion origen: %s&quot;, mimail);
mensaje_operador(textosvarios, textosvarios);
sprintf(textosvarios, &quot;direccion destino: %s&quot;, destino);
mensaje_operador(textosvarios, textosvarios);
sprintf(textosvarios, &quot;servidor correo: %s&quot;, mismtp);
mensaje_operador(textosvarios, textosvarios);
sprintf(textosvarios, &quot;fichero a enviar: %s&quot;, fichero);
mensaje_operador(textosvarios, textosvarios);
}
mensaje_operador(texto1, texto2)
char *texto1, *texto2;
{
char cadena[40];
switch(nivellog)
{
case 0 : break;
case 1 :
memset(cadena, 0, sizeof(cadena));
poncolor(que_color, cadena);
printf(&quot;%s\n&quot;, cadena);
printf(&quot;\033[%02d;%02df \n&quot;, lin, pos);
printf(&quot;\033[%02d;%02df%s\n&quot;, lin, pos, texto1);
memset(cadena, 0, sizeof(cadena));
poncolor(0, cadena);
printf(&quot;%s\n&quot;, cadena);
break;
case 2 : printf(&quot;%s\n&quot;, texto2);
break;
case 3 : fprintf(fplog, &quot;%s\n&quot;, texto2);
break;
}
}

poncolor(quecolor, cadena)
int quecolor;
char *cadena;
{
char cadenaaux[50];
int fondo, texto, alta;
if(quecolor==0)
{
strcat(cadena,&quot;\033[37m\033[40m\033[0m&quot;);
return(0);
}
if(quecolor < 32)
quecolor=quecolor+32;
fondo=quecolor/32;
quecolor=quecolor%32;

if (quecolor > 8)
{
alta=1;
quecolor=quecolor-8;
}
else
{
alta=0;
}
if(alta==1)
{
strcpy(cadena, &quot;\033[0;1m&quot;);
}
else
{
strcpy(cadena,&quot;\033[0m&quot;);
}
sprintf(cadenaaux,&quot;\033[%02dm\033[%02dm&quot;, fondos[fondo], textos[quecolor]);
strcat(cadena, cadenaaux);
return(0);
}



 
jdelgado:

Thanks. I'll play with this and see if I can set it up. May have questions.

fdf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top