Sending email with UTL_MAIL fails(ORA-24247) when call is made from a procedure.

 

Sending email with UTL_MAIL fails(ORA-24247) when call is made from a procedure.


24247. 00000 -  "network access denied by access control list (ACL)"



SHOW parameter smtp

NAME            TYPE   VALUE                                       

--------------- ------ --------------------------------------------

smtp_out_server string ficticious.com

 

sending emails with UTL_MAIL.send_attach_varchar2 is working perfectly fine, but wrapping UTL_MAIL.send_attach_varchar2 in a procedure compiles successfully but executing the procedure ends up in ORA-24247 error.

Wrapper procedure for UTL_MAIL.send_attach_varchar2

create or replace procedure       snd_email_atch

is

begin

  UTL_MAIL.send_attach_varchar2 (

    sender       => 'sendemail@ficticious.com',

    recipients   => 'sendemail@ficticious.com',

    cc           => 'scandata@ficticious.com',

    bcc          => 'sendemail@ficticious.com',

    subject      => 'email from procedure',

    message      => 'email from a procedure works',

    attachment   => 'attachment content goes here.',

    att_filename => 'test_attachment.txt'   

  );

END;

 

exec send_email_attach

 

error starting at line : 3 in command -

BEGIN snd_email_atch; END;

Error report -

ORA-24247: network access denied by access control list (ACL)

ORA-06512: at "SYS.UTL_MAIL", line 662

ORA-06512: at "SYS.UTL_MAIL", line 713

ORA-06512: at "TEST. SND_EMAIL_ATCH ", line 4

ORA-06512: at line 1

24247. 00000 -  "network access denied by access control list (ACL)"

*Cause:    No access control list (ACL) has been assigned to the target

           host or the privilege necessary to access the target host has not

           been granted to the user in the access control list.

*Action:   Ensure that an access control list (ACL) has been assigned to

           the target host and the privilege necessary to access the target

           host has been granted to the user.

 

 

Check existing host_aces

 

select host,principal,privilege,grant_type from dba_host_aces;  

 

HOST     PRINCIPAL           PRIVILEGE           GRANT_TYPE

*             GSMADMIN_INTERNAL  RESOLVE              GRANT

 

Granting the Access Control List privilege directly to the user instead of granting through the role will solve the issue

 

BEGIN

DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE

(

  HOST       => 'ficticious-com’,

  LOWER_PORT => NULL,

  UPPER_PORT => NULL,

  ACE        => XS$ACE_TYPE(

                             PRIVILEGE_LIST => xs$name_list('smtp'),

                             PRINCIPAL_NAME => 'TEST',

                             PRINCIPAL_TYPE => xs_acl.ptype_db

                           )

);

EXCEPTION WHEN OTHERS THEN

  DBMS_OUTPUT.PUT_LINE('Error while granting ACL :'|| SQLERRM);

END;

/

 after adding new ACE

select host,principal,privilege,grant_type from dba_host_aces;  

 

HOST                         PRINCIPAL                           PRIVILEGE           GRANT_TYPE

*                                 GSMADMIN_INTERNAL  RESOLVE                  GRANT

ficticious-com          TEST                                      SMTP                         GRANT

 

Now the wrapper procedure should execute successfully sending email

exec snd_email_atch

 

Reference:

ORA-24247 Calling UTL_SMTP or UTL_HTTP or UTL_TCP in a Stored Procedure when ACL Assigned to a Role (Doc ID 754909.1)

ACL creation fails with ORA-24245: invalid network privilege and ORA-06512: at "SYS.DBMS_NETWORK_ACL_ADMIN" (Doc ID 2631322.1)


Note: this is how i have resoled the issue, Always welcome to comment better solution or corrections.



Comments

Popular posts from this blog

Error processing request - Contact your application administrator apex 20.1

APP-FND-01436: List of Values cannot find any values for you to choose error from concurrent request program parameter (R12 12.1.3)

WEB ADI - issues encountered during initial access