Oracle APEX: Send Emails from different domains in OCI using OCI Email Delivery service
I recently came across a customer requirement to send email from different domains from their Oracle APEX application. Now, let us see how to achieve this.
For this I have followed the below set of steps:
- Created SMTP credentials for the user and saved the Username & Password (Identity → Domains → <Your Domain> → Users → <Your User> → Resources → SMTP Credentials → Generate credentials).
2. Created a Public Zone with the domain name “sanbvsrk.info”. (Networking → DNS Management → Zones)
3. Created an Email Domain with domain name “sanbvsrk.info”. (Developer Services → Application Integration → Email Delivery → Email Domains)
4. Once Email Domain is created, click open it and click on “Add DKIM”. Give a DKIM Selector (I gave ‘01-in-202406'), copy the CNAME Record (01-in-blr-202406._domainkey.sanbvsrk.info.) & CNAME Value which we will use in creating a CNAME entry in Zones and in customer DNS (i.e., in sanbvsrk.info).
5. Click open the Zone created in Step2, click on Manage Records → Add record. Here Name would be CNAME Record excluding the Domain Name part i.e., Name here would be ‘01-in-blr-202406._domainkey’, Type should be CNAME and Target should be CNAME value generated in step4 and then click on Add Record.
6. Repeat Step5, to create a similar entry in Customer DNS.
7. Give it a couple of minutes for this to reflect and once done, under Email Domains for the created DKIM (in Step4), you should see both Customer DNS Status & DKIM Signing Status as “Active”.
8. Now, add the sender email address under “Approved Senders” (Developer Services → Application Integration → Email Delivery → Approved Senders).
9. Now, let us login to Oracle ADB Web SQL Developer Page to run the below commands using which you are setting the Parameters like SMTP Host (Developer Services → Application Integration → Email Delivery → Configuration → SMTP Sending Configuration — Public Endpoint), SMTP Username (created in Step1) & SMTP Password (created in Step1).
10. Once done, login to your Oracle APEX instance, go to SQL Workshop and run the below PLSQL block to check if you are able to send email from Oracle APEX via OCI Email Delivery Service or not.
--PLSQL Block from Step9 to set parameters in Oracle ADB (Login with ADMIN credentials)
BEGIN
APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_HOST_ADDRESS', 'smtp.email.us-phoenix-1.oci.oraclecloud.com');
APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_USERNAME', 'ocid1.user.oc1...');
APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_PASSWORD', 'uT)]+');
COMMIT;
END;
/
--PLSQL Block from Step10 to be run from Oracle APEX SQL Workshop to send email
BEGIN
apex_mail.send(p_from => '<email from approved senders of Step8>',
p_to => '<any email ID of your choice',
p_subj => '<email subject>',
p_body => '<email body>');
apex_mail.push_queue();
END;
/
--You can use the below commands to check if the email sent from the above PLQL block is through or stuck
select * from APEX_MAIL_QUEUE --If in queue it will be here
select * from APEX_MAIL_LOG --If sent it will be here
NOTE: This blog is just to showcase that it is possible to send email from different domains in Oracle APEX on OCI ADB. The same can be leveraged from within the Oracle APEX application as well.
!!Happy Reading!!