I need to create a procedure enviar_email_servidores
that calls another pr_envia_email
.
The procedure to be called ( pr_envia_email
) has the function of sending e-mail, and I need the message sent to this email to be the result of a query (eg send e-mail to all servers that make a birthday in the current month ).
Below the procedure code that sends email ( pr_envia_email
)
create or replace PROCEDURE pr_envia_email
(
Arg_Mensagem varchar2,
Arg_Email_Origem varchar2,
Arg_Email_Destino varchar2
)
is
mail_conn UTL_SMTP.connection;
mailhost varchar2(100);
begin
begin
select end_serv_email into mailhost
from srh2.tab_tribunal;
end;
begin
mail_conn := utl_smtp.open_connection(mailhost, 25);
utl_smtp.helo(mail_conn, mailhost);
utl_smtp.mail(mail_conn, Arg_Email_Origem);
utl_smtp.rcpt(mail_conn, Arg_Email_Destino);
utl_smtp.open_data(mail_conn);
utl_smtp.write_data(mail_conn, 'Content-Type: text/html;charset="iso-8859-1' || utl_tcp.crlf );
-- UTL_SMTP.write_data(mail_conn, Arg_Mensagem);
UTL_SMTP.write_raw_data(mail_conn, utl_raw.cast_to_raw(Arg_Mensagem));
UTL_SMTP.close_data(mail_conn);
utl_smtp.quit(mail_conn);
end;
end;