11 Sending Mail with Email Delivery on Autonomous Database
Describes how to send mail using
UTL_SMTP
on Autonomous Database.
Send Mail Using Email Delivery on Autonomous Database
Describes the steps to send email using
UTL_SMTP
on Autonomous Database.
Note:
The only supported email provider is Oracle Cloud Infrastructure Email Delivery service.Note:
When your Autonomous Database instance is configured with a private endpoint, you can set theROUTE_OUTBOUND_CONNECTIONS
database parameter to 'PRIVATE_ENDPOINT
' to specify that all
outgoing UTL_SMTP
connections are subject to the Autonomous Database instance private
endpoint VCN's egress rules. See Enhanced Security for Outbound Connections with Private Endpoints for more information.
See UTL_SMTP for information on
UTL_SMTP
.
See PL/SQL Packages for UTL_SMTP
restrictions with Autonomous Database.
SMTP Send Mail Sample Code
Shows sample code for sending mail with UTL_SMTP
on Autonomous Database.
CREATE OR REPLACE PROCEDURE SEND_MAIL (
msg_to varchar2,
msg_subject varchar2,
msg_text varchar2 )
IS
mail_conn utl_smtp.connection;
username varchar2(1000):= 'ocid1.user.oc1.username';
passwd varchar2(50):= 'password';
msg_from varchar2(50) := 'adam@example.com';
mailhost VARCHAR2(50) := 'smtp.us-ashburn-1.oraclecloud.com';
BEGIN
mail_conn := UTL_smtp.open_connection(mailhost, 587);
utl_smtp.starttls(mail_conn);
UTL_SMTP.AUTH(mail_conn, username, passwd, schemes => 'PLAIN');
utl_smtp.mail(mail_conn, msg_from);
utl_smtp.rcpt(mail_conn, msg_to);
UTL_smtp.open_data(mail_conn);
UTL_SMTP.write_data(mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || UTL_TCP.crlf);
UTL_SMTP.write_data(mail_conn, 'To: ' || msg_to || UTL_TCP.crlf);
UTL_SMTP.write_data(mail_conn, 'From: ' || msg_from || UTL_TCP.crlf);
UTL_SMTP.write_data(mail_conn, 'Subject: ' || msg_subject || UTL_TCP.crlf);
UTL_SMTP.write_data(mail_conn, 'Reply-To: ' || msg_to || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_data(mail_conn, msg_text || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_smtp.close_data(mail_conn);
UTL_smtp.quit(mail_conn);
EXCEPTION
WHEN UTL_smtp.transient_error OR UTL_smtp.permanent_error THEN
UTL_smtp.quit(mail_conn);
dbms_output.put_line(sqlerrm);
WHEN OTHERS THEN
UTL_smtp.quit(mail_conn);
dbms_output.put_line(sqlerrm);
END;
/
Where:
-
username: specifies the SMTP credential username from Step 2 in Send Mail Using Email Delivery on Autonomous Database.
-
passwd: specifies the SMTP credential password from Step 2 in Send Mail Using Email Delivery on Autonomous Database.
-
msg_from: specifies one of the approved senders from Step 3 in Send Mail Using Email Delivery on Autonomous Database.
-
mailhost: specifies the SMTP Connection Endpoint from Step 1 in Send Mail Using Email Delivery on Autonomous Database.