Enviar e-mail desde forms 9i

Hola:
Quisiera enviar un correo desde forms 9i, con un fichero atachado. Sin el fichero sique sabemos hacerlo, pero con el fichero no envía nada.
El procedimiento es el siguiente:
PROCEDURE SEND_MAIL (MSG_FROM VARCHAR2 , -- MAIL BOX SENDING THE EMAIL
MSG_TO VARCHAR2 , -- MAIL BOX RECIEVING THE EMAIL
MSG_SUBJECT VARCHAR2 , -- EMAIL SUBJECT (Asunto del correo)
MSG_TEXT VARCHAR2 , -- TEXT OF THE EMAIL MESSAGE.
FILE_PATH VARCHAR2 DEFAULT NULL, -- RUTA EN LA QUE SE ENCUENTRA EL FICHERO ADJUNTO
V_OUTPUT1 VARCHAR2 DEFAULT NULL) -- SHOULD BE THE FILE NAME
IS
CONN UTL_TCP.CONNECTION;
RC INTEGER;
CRLF VARCHAR2(2):= CHR(13)||CHR(10);
MESG VARCHAR2( 32767 );
V_OUTPUT_FILE1 UTL_FILE.FILE_TYPE;
-- FILETXTBUF VARCHAR2(1000);
-- FILETXT VARCHAR2(1000);
MAILHOST VARCHAR2(30) := 'MAIL_VLC';
BEGIN
DBMS_OUTPUT.PUT_LINE('ENTRO');
DBMS_OUTPUT.PUT_LINE('FILE_PATH:'||FILE_PATH||' ; V_OUTPUT1 :'||V_OUTPUT1);
V_OUTPUT_FILE1 := UTL_FILE.FOPEN(FILE_PATH, V_OUTPUT1, 'R');
DBMS_OUTPUT.PUT_LINE('FICHERO ABIERTO');
LOOP
DBMS_OUTPUT.PUT_LINE('ENTRO EN EL LOOP');
BEGIN
UTL_FILE.GET_LINE(V_OUTPUT_FILE1,FILETXTBUF);
FILETXT:=FILETXT||FILETXTBUF;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT;
END;
END LOOP;
UTL_FILE.FCLOSE(V_OUTPUT_FILE1);
DBMS_OUTPUT.PUT_LINE('FICHERO CERRADO.FILETXT:'||FILETXT);
CONN := UTL_TCP.OPEN_CONNECTION(MAILHOST, 25); ----- OPEN SMTP PORT CONNECTION
RC := UTL_TCP.WRITE_LINE(CONN, 'HELO '||MAILHOST); ----- PERFORMS HANDSHAKING WITH SMTP SERVER
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'EHLO '||mailhost); ----- PERFORMS HANDSHAKING WITH SMTP SERVER, INCLUDING EXTRA INFORMATION
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'MAIL FROM: '||MSG_FROM); ----- MAIL BOX SENDING THE EMAIL
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'RCPT TO: '||MSG_TO); ----- MAIL BOX RECIEVING THE EMAIL
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'DATA'); ----- EMAIL MESSAGE BODY START
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'DATE: '||TO_CHAR( SYSDATE, 'DD MON YY HH24:MI:SS' ));
RC := UTL_TCP.WRITE_LINE(CONN, 'FROM: '||MSG_FROM||' <'||MSG_FROM||'>');
RC := UTL_TCP.WRITE_LINE(CONN, 'MIME-VERSION: 1.0');
RC := UTL_TCP.WRITE_LINE(CONN, 'TO: '||MSG_TO||' <'||MSG_TO||'>');
RC := UTL_TCP.WRITE_LINE(CONN, 'SUBJECT: '||MSG_SUBJECT);
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-TYPE: MULTIPART/MIXED;'); ----- INDICATES THAT THE BODY CONSISTS OF MORE THAN ONE PART
RC := UTL_TCP.WRITE_LINE(CONN, ' BOUNDARY="-----SECBOUND"'); ----- SEPERATOR USED TO SEPERATE THE BODY PARTS
RC := UTL_TCP.WRITE_LINE(CONN, ''); ----- INSERTS A BLANK LINE. PART OF THE MIME FORMAT AND NONE OF THEM SHOULD BE REMOVED.
RC := UTL_TCP.WRITE_LINE(CONN, '-------SECBOUND');
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-TYPE: TEXT/PLAIN'); ----- 1ST BODY PART. EMAIL TEXT MESSAGE
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-TRANSFER-ENCODING: 7BIT');
RC := UTL_TCP.WRITE_LINE(CONN, '');
RC := UTL_TCP.WRITE_LINE(CONN, MSG_TEXT); ----- TEXT OF EMAIL MESSAGE
RC := UTL_TCP.WRITE_LINE(CONN, '');
RC := UTL_TCP.WRITE_LINE(CONN, '-------SECBOUND');
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-TYPE: TEXT/PLAIN;'); ----- 2ND BODY PART.
RC := UTL_TCP.WRITE_LINE(CONN, ' NAME="'||V_OUTPUT1||'"');
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-TRANSFER_ENCODING: 8BIT');
RC := UTL_TCP.WRITE_LINE(CONN, 'CONTENT-DISPOSITION: ATTACHMENT;'); ----- INDICATES THAT THIS IS AN ATTACHMENT
RC := UTL_TCP.WRITE_LINE(CONN, ' FILENAME="'||V_OUTPUT1||'"'); ----- SUGGESTED FILE NAME FOR ATTACHMENT
RC := UTL_TCP.WRITE_LINE(CONN, '');
RC := UTL_TCP.WRITE_LINE(CONN, FILETXT);
RC := UTL_TCP.WRITE_LINE(CONN, '-------SECBOUND--');
RC := UTL_TCP.WRITE_LINE(CONN, '');
RC := UTL_TCP.WRITE_LINE(CONN, '.'); ----- EMAIL MESSAGE BODY END
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
RC := UTL_TCP.WRITE_LINE(CONN, 'QUIT'); ----- ENDS EMAIL TRANSACTION
DBMS_OUTPUT.PUT_LINE(UTL_TCP.GET_LINE(CONN, TRUE));
UTL_TCP.CLOSE_CONNECTION(CONN); ----- CLOSE SMTP PORT CONNECTION
EXCEPTION
WHEN UTL_FILE.INVALID_PATH
THEN dbms_output.put_line ('invalid_path');
WHEN UTL_FILE.INVALID_MODE
THEN dbms_output.put_line ('invalid_mode');
WHEN UTL_FILE.INVALID_FILEHANDLE
THEN dbms_output.put_line ('invalid_filehandle');
WHEN UTL_FILE.INVALID_OPERATION
THEN dbms_output.put_line ('invalid_operation');
WHEN UTL_FILE.READ_ERROR
THEN dbms_output.put_line ('read_error');
WHEN UTL_FILE.WRITE_ERROR
THEN dbms_output.put_line ('write_error');
WHEN UTL_FILE.INTERNAL_ERROR
THEN dbms_output.put_line ('internal_error');
WHEN OTHERS THEN
dbms_output.put_line('SQLCODE: ' ||(SQLCODE));
dbms_output.put_line('SQLERRM: ' || SQLERRM);
END;
Gracias

1 Respuesta

Respuesta
1
Tal ves puedas darle una mirada a este codigo de ejemplo.
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/maildemo_sql.txt

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas