send email in oracle apex?

968 views Asked by At

In my application, I have table users in which every user have an email address. I've created a send mail process, so the users can receive and send email to each other, that is activated when I press a button but I don't know if the mail has been sent because I get error ORA-24247: network access denied by access control list (ACL) even if I created ACL and I gave permission. I'm using apex 4.0.2

enter image description here

1

There are 1 answers

0
Brian Leach On

Oracle email requires the setup of an access control list (ACL) to allow Oracle to connect to your mail server. Here is some sample code that will create an ACL to allow SCHEMA1 and SCHEMA2 to use the UTL_SMTP and UTL_MAIL packages.

  • L_ACL is a string that your pick
  • SCHEMA1 and SCHEMA2 are the schemas that will be sending email
  • g_mailhost is the name of your email server that must already be set up to forward mail.

     DECLARE
       l_acl         VARCHAR2 (30) := 'utl_smtp.xml';
       l_principal   VARCHAR2 (30) := 'SCHEMA1';
       l_principal2  VARCHAR2 (30) := 'SCHEMA2';
       g_mailhost    VARCHAR2 (60) := 'mail.mydomain.com';
    BEGIN
        DBMS_NETWORK_ACL_ADMIN.drop_acl (l_acl);
    
       DBMS_NETWORK_ACL_ADMIN.create_acl (
          acl         => l_acl
        , description => 'Allow use of utl_smtp'
        , principal   => l_principal
        , is_grant    => TRUE
        , privilege   => 'connect'
       );
    
       DBMS_NETWORK_ACL_ADMIN.assign_acl (acl => l_acl, HOST => g_mailhost);
    
    
       COMMIT;
       DBMS_NETWORK_ACL_ADMIN.add_privilege (
          acl       => l_acl
        , principal => l_principal2
        , is_grant  => TRUE
        , privilege => 'connect'
       );
       COMMIT;
    END;