Pré-requisitos:
- Serviço de enfileiramento de mensagens SMTP instalado no Windows.
- Caso possua algum firewall ou anti-vírus, verifique se o mesmo não impede envios pela porta 25 (SMTP)
- Caso possua algum firewall ou anti-vírus, verifique se o mesmo não impede envios pela porta 25 (SMTP)
Procedure:
create or replaceprocedure email_html (from_name varchar2, to_name varchar2, subject varchar2, message varchar2) is
/***********************************************************************
Criacao : Anderson Ayres
Objetivo : Envia um email em formato HTML
Observacoes :
———————————————————————-
Historico das alteracoes:
———————————————————————-
Alteracao : 10/03/2010 por Anderson Ayres Bittencourt
Objetivo : Alteração de método de autenticação no servidor de email.
Observacoes : Os métodos possíveis de autenticação são: (validar qual o cliente utiliza)
UTL_SMTP.COMMAND(conn, ‘STARTTLS’); — comum em Exchange 2010.
UTL_SMTP.COMMAND(conn, ‘AUTH LOGIN’); — comum em Exchange 2007 e o mais utilizado por outros servidores de e-mail.
UTL_SMTP.COMMAND(conn, ‘AUTH NTLM’); — método para autenticação NTLM
UTL_SMTP.COMMAND(conn, ‘AUTH PLAIN’); — pouco utilizado… inseguro.
************************************************************************/v_smtp_server varchar2(20) := ‘mail.superti.org‘;
v_smtp_server_port number := 25;
v_directory_name varchar2(100);
v_file_name varchar2(100);
v_line varchar2(1000);
crlf varchar2(2):= chr(13) || chr(10);
mesg varchar2(32767);
conn UTL_SMTP.CONNECTION;
type varchar2_table is table of varchar2(200) index by binary_integer;begin
– Open the SMTP connection …
– ————————
conn:= utl_smtp.open_connection( v_smtp_server, v_smtp_server_port );– Initial handshaking …
– ——————-
utl_smtp.helo( conn, v_smtp_server );UTL_SMTP.COMMAND(conn, ‘AUTH LOGIN’);
UTL_SMTP.COMMAND(conn, UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(UTL_RAW.CAST_TO_RAW(‘usuário_smtp‘))));
UTL_SMTP.COMMAND(conn, UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(UTL_RAW.CAST_TO_RAW(‘senha‘))));
utl_smtp.mail( conn, ‘remetente‘ );
utl_smtp.rcpt( conn, to_name );
utl_smtp.rcpt( conn, to_name );
utl_smtp.open_data (conn);
– build the start of the mail message …
– ———————————–
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Mime-Version: 1.0′ || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Content-Type: Text/html; charset=ISO-8859-1′ || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘From:remetente@superti.org‘ ||utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Date:’ || TO_CHAR( SYSDATE, ‘dd Mon yy hh24:mi:ss’ ) || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘To:’ || to_name || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Subject:’ || subject || utl_tcp.CRLF));
– ———————————–
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Mime-Version: 1.0′ || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Content-Type: Text/html; charset=ISO-8859-1′ || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘From:remetente@superti.org‘ ||utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Date:’ || TO_CHAR( SYSDATE, ‘dd Mon yy hh24:mi:ss’ ) || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘To:’ || to_name || utl_tcp.CRLF));
UTL_SMTP.WRITE_RAW_DATA( conn,UTL_RAW.CAST_TO_RAW(‘Subject:’ || subject || utl_tcp.CRLF));
utl_smtp.write_data(conn,’ ‘ || utl_tcp.CRLF);
utl_smtp.write_raw_data(conn,utl_raw.cast_to_raw(utl_tcp.CRLF||message));
utl_smtp.close_data( conn );
utl_smtp.quit( conn );
end;
utl_smtp.write_raw_data(conn,utl_raw.cast_to_raw(utl_tcp.CRLF||message));
utl_smtp.close_data( conn );
utl_smtp.quit( conn );
end;
Nenhum comentário:
Postar um comentário