lo enviaremos via gmail:
nota: "en tu caso seria configurarlo con tu servidor de correo si lo poses"
primero necesitamos un tunnel vpn a
gmail "si poses un correo propio es
opcional
esta parte.":
https://www.stunnel.org/downloads.html
una vez descargado lo instalamos en el servidor donde este oracle instalado
y nos vamos a la ruta de instalacion:
creamos un archivo llamado
stunnel.conf
dentro tendra lo siguiente y reiniciamos la aplicacion:
[SSMTP]
CLIENT = YES
ACCEPT = 1925
CONNECT = SMTP.GMAIL.COM:465
ahora necesitaremos ir a gmail.com
https://myaccount.google.com/security
al final en Permitir el acceso de aplicaciones poco seguras:
colocamos que SI
ahora necesitaremos configurar las reglas de acl:
-- create acl
begin
dbms_network_acl_admin.create_acl (
acl => 'gmail.xml',
description => 'Normal Access',
principal => 'CONNECT',
is_grant => TRUE,
privilege => 'connect',
start_date => null,
end_date => null
);
end;
/
-- add priviliege to acl
begin
dbms_network_acl_admin.add_privilege (
acl => 'gmail.xml',
principal => 'PUBLIC',
is_grant => TRUE,
privilege => 'connect',
start_date => null,
end_date => null);
end;
/
-- assign host, port to acl
begin
dbms_network_acl_admin.assign_acl (
acl => 'gmail.xml',
host => 'localhost',
lower_port => 1925,
upper_port => 1925);
end;
/
ahora necesitaremos crear el paquete:
create or replace package send_mail
is
g_smtp_host varchar2 (256) := 'localhost';
g_smtp_port pls_integer := 1925;
g_smtp_domain varchar2 (256) := 'gmail.com';
g_mailer_id constant varchar2 (256) := 'Mailer by Oracle UTL_SMTP';
-- send mail using UTL_SMTP
procedure mail (
p_name in varchar2
, p_sender in varchar2
, p_recipient in varchar2
, p_subject in varchar2
, p_message in varchar2
);
end;
/
create or replace package body send_mail
is
-- Write a MIME header
procedure write_mime_header (
p_conn in out nocopy utl_smtp.connection
, p_name in varchar2
, p_value in varchar2
)
is
begin
utl_smtp.write_data ( p_conn
, p_name || ': ' || p_value || utl_tcp.crlf
);
end;
procedure mail (
p_name in varchar2
, p_sender in varchar2
, p_recipient in varchar2
, p_subject in varchar2
, p_message in varchar2
)
is
l_conn utl_smtp.connection;
nls_charset varchar2(255);
begin
-- get characterset
select value
into nls_charset
from nls_database_parameters
where parameter = 'NLS_CHARACTERSET';
-- establish connection and autheticate
l_conn := utl_smtp.open_connection (g_smtp_host, g_smtp_port);
utl_smtp.ehlo(l_conn, g_smtp_domain);
utl_smtp.command(l_conn, 'auth login');
utl_smtp.command(l_conn,utl_encode.text_encode('[email protected]', nls_charset, 1));
utl_smtp.command(l_conn, utl_encode.text_encode('passworgmail', nls_charset, 1));
-- set from/recipient
utl_smtp.command(l_conn, 'MAIL FROM:<'||p_sender||'>');
utl_smtp.command(l_conn, 'RCPT TO: <'||p_recipient||'>');
-- write mime headers
utl_smtp.open_data (l_conn);
write_mime_header (l_conn, 'Reply-To', p_sender);
write_mime_header (l_conn, 'From',''|| p_name ||'<'||p_sender||'>');
write_mime_header (l_conn, 'To', p_recipient);
write_mime_header (l_conn, 'Subject', p_subject);
write_mime_header (l_conn, 'Content-Type', 'text/html');
--write_mime_header (l_conn, 'X-Mailer', g_mailer_id);
utl_smtp.write_data (l_conn, utl_tcp.crlf);
-- write message body
utl_smtp.write_data (l_conn, p_message);
utl_smtp.close_data (l_conn);
-- end connection
utl_smtp.quit (l_conn);
exception
when others
then
begin
utl_smtp.quit(l_conn);
exception
when others then
null;
end;
raise_application_error(-20000,'Failed to send mail due to the following error: ' || sqlerrm);
end;
end;
/
por ultimo provamos:
begin
send_mail.mail('name sender.','[email protected]', '[email protected]', 'email example', '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1 style="color:blue;">ejemplo envio de correo</h1>
</body>
</html>');
end;
/