MattsBits
MattsBits

MattsBits

Send Emails From An APEX Application  

by Matt Hawkins, 15/04/2009
Categories : APEX

In order to send emails from Oracle APEX you can use the APEX_MAIL API.

You can send plain text or HTML emails while defining the sender, recipients and bccs.

Note : The package is built using the Oracle supplied UTL_SMTP package so the UTL_SMTP package must be installed and functioning in order to use APEX_MAIL.

Here is an example function that sends a plain text email and an HTML email :


DECLARE

  v_subject    VARCHAR2(100);
  v_sender     VARCHAR2(100);
  v_recipient  VARCHAR2(100);
  v_cc         VARCHAR2(100);
  v_bcc        VARCHAR2(100);
  v_body       VARCHAR2(4000);
  v_body_html  VARCHAR2(4000);

BEGIN

  v_subject   := 'Email Subject';
  v_sender    := 'sender@example.com';
  v_recipient := 'recipient@example.com';
  v_cc        := '';
  v_bcc       := '';

  v_body      :=  'Some text' || chr(10) || 'more text here';
  v_body_html := 'Some text<br />more text here';

  -- Send plain text email
  APEX_MAIL.SEND(
    P_TO       => v_recipient,
    P_FROM     => v_sender,
    P_CC       => v_cc,
    P_BCC      => v_bcc,
    P_SUBJ     => v_subject,
    P_BODY     => v_body);

  -- Send HTML email
  APEX_MAIL.SEND(
    P_TO        => v_recipient,
    P_FROM      => v_sender,
    P_CC        => v_cc,
    P_BCC       => v_bcc,
    P_SUBJ      => v_subject,
    P_BODY      => v_body,
    P_BODY_HTML => v_body_html);

END;


Make sure v_body is defined so that it can hold all of your message text!

You can add the following code to flush the mail queue which will force your email to be sent immediately :

  -- Flush queue
  APEX_MAIL.PUSH_QUEUE;

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2017