Send Email from Oracle APEX

You can use the APEX_MAIL package to send emails from Oracle APEX applications deployed in Autonomous Database.

Before you use APEX_MAIL you must configure an email provider in your Oracle APEX instance. The only supported email provider is Oracle Cloud Infrastructure Email Delivery service.

Note:

Third-party email providers are not supported.

To enable APEX_MAIL functionality in your APEX instance in Autonomous Database:

  1. Identify the SMTP connection endpoint for Email Delivery. You configure the endpoint as the SMTP Host in your APEX instance in Step 4. You may need to subscribe to additional Oracle Cloud Infrastructure regions if Email Delivery is not available in your current region. See Configure SMTP Connection for more information.
  2. Generate SMTP credentials for Email Delivery. Your APEX instance uses credentials to authenticate with Email Delivery servers when you send email. See Generate SMTP Credentials for a User for more information.
  3. Create an approved sender for Email Delivery. You need to complete this step for all email addresses you use as the "From" with APEX_MAIL.SEND calls, as the Application Email From Address in your apps, or in the SMTP_FROM instance parameter. See Managing Approved Senders for more information.
  4. Connect to your Autonomous Database as ADMIN user using a SQL client and configure the following SMTP parameters using APEX_INSTANCE_ADMIN.SET_PARAMETER:
    • SMTP_HOST_ADDRESS: Specifies the SMTP connection endpoint from Step 1.
    • SMTP_USERNAME: Specifies the SMTP credential user name from Step 2.
    • SMTP_PASSWORD: Specifies the SMTP credential password from Step 2.
    • Keep default values for SMTP_HOST_PORT parameter (587) and SMTP_TLS_MODE parameter (STARTTLS).
    For example:
    BEGIN
        APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_HOST_ADDRESS', 'smtp.us-phoenix-1.oraclecloud.com');
        APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_USERNAME', 'ocid1.user.oc1.username');
        APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_PASSWORD', 'password');
        COMMIT;
    END;
    /
  5. Validate the email configuration settings using a SQL client.
    BEGIN
        APEX_INSTANCE_ADMIN.VALIDATE_EMAIL_CONFIG;
    END;
    /

    If any errors are reported (for example, "ORA-29279: SMTP permanent error: 535 Authentication credentials invalid"), adjust the SMTP parameters and repeat the validation step.

  6. Send a test email using APEX SQL Workshop, SQL Commands specifying one of the approved senders from Step 3 as "From". For example:
    BEGIN
        APEX_MAIL.SEND(p_from => 'alice@example.com',
                       p_to   => 'bob@example.com',
                       p_subj => 'Email from Oracle Autonomous Database',
                       p_body => 'Sent using APEX_MAIL');
    END;
    /
  7. To monitor email delivery in your APEX instance:
    1. Sign in to APEX Administration Services.
    2. Open the Manage Instance page.
    3. Click the Mail Queue link in the Manage Meta Data section.
    Alternatively, query APEX_MAIL_QUEUE and APEX_MAIL_LOG views using a SQL client.

Note:

There is a default limit of 5,000 emails per workspace in a 24-hour period. You can update or remove this limit in Oracle APEX Administration Services or by setting the WORKSPACE_EMAIL_MAXIMUM instance parameter. Oracle Cloud Infrastructure Email Delivery may impose additional limitations.

An approved sender must be set up for all “From:” addresses sending mail though Oracle Cloud Infrastructure, or mail will be rejected. There are limitations on approved senders with Oracle Cloud Infrastructure Email Delivery. See Managing Approved Senders for more information.

For more information, see: