Minha função:
sender VARCHAR2(80);
recipient VARCHAR2(80);
subject VARCHAR2(300);
message VARCHAR2(5000);
mailhost VARCHAR2(30);
crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
mesg VARCHAR2( 1000 );
cursor c1 is select des_login from sgi.cad_entidade
where id_cad_entidade in
(select id_cad_entidade from ofn_colaborador_email where id_cad_emp_gerencial = :new.ID_CAD_EMP_GERENCIAL);
mail_conn utl_smtp.connection;
begin
if (:new.FLG_TRAVA = 'S' and :new.FLG_EMAIL = 'S' and :new.FLG_OPCAO_ENVIO = 'Trava Real') then
for reg in c1 loop
if (reg.des_login is not null) then
select sgi.pck_sgi_ldap.f_retorna_email(reg.des_login) into recipient from dual;
if (recipient is not null) then
mailhost:='smtp.icec.com.br';
mail_conn := utl_smtp.open_connection(mailhost, 25);
sender:='danilo.marchi@orgicec.com.br';
subject:='Trava de Real';
message:='teste1';
mesg:= 'Date: ' || TO_CHAR(to_date(:new.mês_ANO, 'dd/mm/rrrr'), 'Mon/rrrr') || ' ' || to_char(SYSDATE, 'hh24:mi:ss') || crlf ||
'From: <'||sender||'>' || crlf ||
'Subject: '||subject || crlf ||
'To: '||recipient || crlf ||
'O ralizado do mês de ' || to_char(:new.mês_ANO, 'Month') || ' de ' || to_char(:new.mês_ANO, 'rrrr') || ' já está finalizado.' || crlf ||
' '||crlf|| crlf||
'' || :new.mensagem ||
' '||crlf|| crlf||
'Caso tenham alguma dúvida, por favor, entrem em contado.'||crlf||
'Obrigado .'||crlf||
' ' ||crlf|| crlf||
'Danilo Marchi'||crlf||
'Controladoria Financeira Corporativo'||crlf||
'Tel. (17) 2136-9944'||crlf||
'Cel. (17) 9745-7651'||crlf||
'Visite nosso site: www.icec.com.br'||crlf||
' '||crlf||message;
utl_smtp.helo(mail_conn, mailhost);
utl_smtp.mail(mail_conn, sender);
utl_smtp.rcpt(mail_conn, recipient);
utl_smtp.data(mail_conn, mesg);
utl_smtp.quit(mail_conn);
utl_smtp.write_raw_data
end if;
end if;
end loop;
end if;