Send Email from APEX deployed in Oracle Autonomous Database

In the Oracle Cloud, you can provision an Autonomous Database in minutes and start developing your APEX application immediatelly. If you don’t have an Oracle Cloud Account, register for the Always Free resources.

From APEX, you can use the APEX_MAIL package to send emails using Oracle Cloud Infrastructure Email Delivery service.

Check how easy it is to configure!!!

Step 1: In Identity and Access Management (IAM) create a user, a group MailGroup, add the user to the group, and create a policy MailPolicy with the following statement:

Allow group MailGroup to use approved-senders in compartment CompartmentA

Step 2: add as approved sender in Email Delivery

Select CompartmentA from the top-down menu on the left side, click on Create Approved Sender, and enter the email address.

Step 3: Create the SMTP credentials for the user. From the user’s details page, click SMTP Credentials, and then Create SMTP Credentials

After entering a name, you will be prompted with a username and password. Copy these values to a safe place as there will not be displayed again.

Step 4: Connect to you Autonomous Database as ADMIN user and execute the following command using the username and password just got generated in step 3:


You also could use a different SMTP Connection Endpoint than Frankfurt.

Step 5: Connect to APEX SQL Workshop and run the following command using the mail address from Step 2 in the p_from parameter:

APEX_MAIL.SEND(p_from => '',
p_to  => '',
p_subj => 'Email from Oracle Autonomous Database',
p_body => 'Sent using APEX_MAIL');

You’re done! 🙂

In case something went wrong and the email has not been sent, check the mail queue in the database by querying:

SELECT mail_to, mail_send_error FROM apex_mail_queue;

Check this page for more details!

Would you like to get notified when the next post is published?