CREATE OR REPLACE PACKAGE mip_email IS

  -- Author  : MULLENMD
  -- Created : 02/11/2007 13:46:43
  -- Purpose : Allow the system to send emails.

  g_from_address CONSTANT VARCHAR2(50) := cout_system_configuration.get_configuration_item('EMAIL_FROM_ADDRESS');

  PROCEDURE send_email_plain_text(p_recipient IN VARCHAR2
                                 ,p_from      IN VARCHAR2 DEFAULT g_from_address
                                 ,p_body      IN VARCHAR2
                                 ,p_subject   IN VARCHAR2);

  PROCEDURE send_email_vchar(p_recipient IN VARCHAR2
                            ,p_from      IN VARCHAR2 DEFAULT g_from_address
                            ,p_body      IN VARCHAR2
                            ,p_body_html IN VARCHAR2
                            ,p_subject   IN VARCHAR2);

  PROCEDURE send_email_clob(p_recipient IN VARCHAR2
                           ,p_from      IN VARCHAR2 DEFAULT g_from_address
                           ,p_body      IN CLOB
                           ,p_body_html IN CLOB
                           ,p_subject   IN VARCHAR2);

  PROCEDURE add_attachment(p_attachment IN BLOB
                          ,p_filename   IN VARCHAR2
                          ,p_mime_type  IN VARCHAR2);
END mip_email;
/
CREATE OR REPLACE PACKAGE BODY mip_email IS

  g_mail_id NUMBER;
  --
  PROCEDURE send_email_plain_text(p_recipient IN VARCHAR2
                                 ,p_from      IN VARCHAR2 DEFAULT g_from_address
                                 ,p_body      IN VARCHAR2
                                 ,p_subject   IN VARCHAR2) IS
  
  BEGIN
    g_mail_id := apex_mail.send(p_to   => p_recipient
                               ,p_from => p_from
                               ,p_body => p_body
                               ,p_subj => p_subject);
  END send_email_plain_text;
  --

  --
  PROCEDURE send_email_vchar(p_recipient IN VARCHAR2
                            ,p_from      IN VARCHAR2 DEFAULT g_from_address
                            ,p_body      IN VARCHAR2
                            ,p_body_html IN VARCHAR2
                            ,p_subject   IN VARCHAR2) IS
  
  BEGIN
    g_mail_id := apex_mail.send(p_to        => p_recipient
                               ,p_from      => p_from
                               ,p_body      => p_body
                               ,p_body_html => p_body_html
                               ,p_subj      => p_subject);
  END send_email_vchar;
  --

  --
  PROCEDURE send_email_clob(p_recipient IN VARCHAR2
                           ,p_from      IN VARCHAR2 DEFAULT g_from_address
                           ,p_body      IN CLOB
                           ,p_body_html IN CLOB
                           ,p_subject   IN VARCHAR2) IS
  
  BEGIN
    g_mail_id := apex_mail.send(p_to        => p_recipient
                               ,p_from      => p_from
                               ,p_body      => p_body
                               ,p_body_html => p_body_html
                               ,p_subj      => p_subject);
  END send_email_clob;

  PROCEDURE add_attachment(p_attachment IN BLOB
                          ,p_filename   IN VARCHAR2
                          ,p_mime_type  IN VARCHAR2) IS
  BEGIN
    apex_mail.add_attachment(p_mail_id    => g_mail_id
                            ,p_attachment => p_attachment
                            ,p_filename   => p_filename
                            ,p_mime_type  => p_mime_type);
  END add_attachment;
  --
END mip_email;
/
