Oracle UTL_SMTP

The Oracle UTL_SMTP package is designed for sending e-mails over Simple Mail Transfer Protocol (SMTP).

Oracle UTL_SMTP example

CREATE OR REPLACE PROCEDURE send_email (
p_sender    VARCHAR2,
p_recipient VARCHAR2,
p_subject   VARCHAR2,
p_message   VARCHAR2) IS
my_host  VARCHAR2(100) := 'smtp.codertutor.com';
v_mess   VARCHAR2(1000);
email_conn utl_smtp.connection;
BEGIN
email_conn := utl_smtp.open_connection(my_host, 25);
v_mess := 'Message from '|| p_subject ||': '|| p_message;

utl_smtp.helo(email_conn, my_host);
utl_smtp.mail(email_conn, p_sender);
utl_smtp.rcpt(email_conn, p_recipient);
utl_smtp.data(email_conn, v_mess);
utl_smtp.quit(email_conn); 
   
EXCEPTION
WHEN OTHERS THEN
NULL; 
END send_email;