Entrar

OracleBR

Procedure

Inicial - Banco de Códigos

Procedure para envio de e-mail's. Oracle 8.1.6 ou superior

Data de Inclusão: 02/09/2006 | Última Alteração: 02/09/2006
Tipo:Procedure | Enviada por: Moderador Oracle_br (moderador@oraclebr.com.br)


/*********************************************************************************************
*** 'Mailhost' is the name of the remote host when connection is established. The port ***
*** number on which SMTP server is listening is usually 25. ***
*** ***
*** Open_connection(): Allows open connection to an SMTP server. ***
*** Helo(): Performs initial handshaking with SMTP server after connecting. ***
*** Mail(): Initiates a mail transaction with the server. The destination is a mailbox. ***
*** Rcpt(): Specifies the recipient of an email message. ***
*** Data(): Specifies the body of an email message. ***
*** Quit(): Terminates an SMTP session and disconnects from the server ***
*********************************************************************************************/

CREATE OR REPLACE PROCEDURE send_mail( p_mailhost IN VARCHAR2,
p_sender IN VARCHAR2,
p_recipient IN VARCHAR2,
p_subject IN VARCHAR2,
p_message IN VARCHAR2 ) IS

mail_conn UTL_SMTP.CONNECTION;

crlf VARCHAR2( 2 ) := CHR( 13 ) || CHR( 10 );
mesg VARCHAR2( 1000 );

BEGIN
mail_conn := UTL_SMTP.OPEN_CONNECTION( p_mailhost, 25 );

mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From: <' || p_sender || '>' || crlf ||
'Subject: ' || p_subject || crlf ||
'To: ' || p_recipient || crlf ||
'' || crlf ||
p_message;

UTL_SMTP.HELO( mail_conn, p_mailhost );
UTL_SMTP.MAIL( mail_conn, p_sender );
UTL_SMTP.RCPT( mail_conn, p_recipient);
UTL_SMTP.DATA( mail_conn, mesg );
UTL_SMTP.QUIT( mail_conn );
END;
/