How to re-design code with UTL_SMTP - Oracle Apex send mail
NickName:kiric8494 Ask DateTime:2022-06-16T21:25:42

How to re-design code with UTL_SMTP - Oracle Apex send mail

It's been a hard time not able to make my code to work with UTL_SMTP package.

Can some one guide me to change below code and make it work with UTL_SMTP method

I created a mailing application which sends mail to all user on their email id's with an attachment.

Took reference and I built it same exactly like this

https://blogs.oracle.com/apex/post/creating-email-campaign-app-with-oracle-apex

My Code :

    declare 
        l_context apex_exec.t_context;    
        l_emailsidx  pls_integer;
        l_namesids    pls_integer;
        l_region_id number;
    begin
        -- Get the region id for the CUSTOMERS IR region
        select region_id
          into l_region_id
          from apex_application_page_regions
         where application_id = :APP_ID
           and page_id        = 1
           and static_id      = 'CUSTOMERS';
     
        l_context := apex_region.open_query_context (
                            p_page_id => 1,
                            p_region_id => l_region_id );
        -- Get the column positions for EMAIL and NAME columns
        l_emailsidx := apex_exec.get_column_position( l_context, 'EMAIL' );
        l_namesids := apex_exec.get_column_position( l_context, 'NAME' );
        
        -- Loop throught the query of the context
        while apex_exec.next_row( l_context ) loop        
            l_id : = apex_mail.send (
            p_to                 => apex_exec.get_varchar2( l_context, l_emailsidx ),
            p_template_static_id => 'NEW_YEAR_2020_PROMOTION_DUBAI_BRANCH',
            p_placeholders       => '{' ||
            '    "CUSTOMER":'            || apex_json.stringify( apex_exec.get_varchar2( l_context, l_namesids )) ||
            '   ,"START_DATE":'          || apex_json.stringify( :P2_START_DATE ) ||
            '   ,"END_DATE":'            || apex_json.stringify( :P2_END_DATE ) ||        
            '   ,"LOCATION":'            || apex_json.stringify( :P2_LOCATION ) ||        
            '   ,"NOTES":'               || apex_json.stringify( :P2_NOTES ) ||
            '   ,"ITEMS":'               || apex_json.stringify( :P2_ITEMS ) ||
            '   ,"MY_APPLICATION_LINK":' || apex_json.stringify( apex_mail.get_instance_url || apex_page.get_url( 1 )) ||        
            '}' );
         end loop;
         

for rec in (
        select filename, blob_content, mime_type 
          from apex_application_files
         where flow_id = :APP_ID
           and filename = 'apex_logo.png'
    ) 
    loop

        apex_mail.add_attachment(
            p_mail_id    => l_id,
            p_attachment => rec.blob_content,
            p_filename   => rec.filename,
            p_mime_type  => rec.mime_type);
    end loop;

         apex_mail_queue(
             p_smtp_hostname => 'xyz.xmp.it',
             p_smtp_portno   => 45
         )

         apex_exec.close( l_context );
    exception
         when others then
             apex_exec.close( l_context );
         raise; 
    end;

Need to convert my above code below like this

UTL_MAIL.send (
 sender => '[email protected]',
 recipents => '[email protected]',
 cc => '[email protected]',
 subject => 'Testing',
 mime_type => 'text/html',
 message => 'ABC TESTING' 
);

My below code does not support at my end. It throws network access denied as (ACL). Only UTL_SMTP is supported and mail is sent. But below code need to transform as above UTL_SMTP.send method

  l_id : = apex_mail.send (
            p_to                 => apex_exec.get_varchar2( l_context, l_emailsidx ),
            p_template_static_id => 'NEW_YEAR_2020_PROMOTION_DUBAI_BRANCH',
            p_placeholders       => '{' ||
            '    "CUSTOMER":'            || apex_json.stringify( apex_exec.get_varchar2( l_context, l_namesids )) ||
            '   ,"START_DATE":'          || apex_json.stringify( :P2_START_DATE ) ||
            '   ,"END_DATE":'            || apex_json.stringify( :P2_END_DATE ) ||        
            '   ,"LOCATION":'            || apex_json.stringify( :P2_LOCATION ) ||        
            '   ,"NOTES":'               || apex_json.stringify( :P2_NOTES ) ||
            '   ,"ITEMS":'               || apex_json.stringify( :P2_ITEMS ) ||
            '   ,"MY_APPLICATION_LINK":' || apex_json.stringify( apex_mail.get_instance_url || apex_page.get_url( 1 )) ||        
            '}' );
         end loop;
         

for rec in (
        select filename, blob_content, mime_type 
          from apex_application_files
         where flow_id = :APP_ID
           and filename = 'apex_logo.png'
    ) 
    loop

        apex_mail.add_attachment(
            p_mail_id    => l_id,
            p_attachment => rec.blob_content,
            p_filename   => rec.filename,
            p_mime_type  => rec.mime_type);
    end loop;

         apex_mail_queue(
             p_smtp_hostname => 'xyz.xmp.it',
             p_smtp_portno   => 45
         )

Following is the YouTube followed to create the application

https://www.youtube.com/watch?v=aZQ04yjS7rQ

Copyright Notice:Content Author:「kiric8494」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72646645/how-to-re-design-code-with-utl-smtp-oracle-apex-send-mail

More about “How to re-design code with UTL_SMTP - Oracle Apex send mail” related questions

How to re-design code with UTL_SMTP - Oracle Apex send mail

It's been a hard time not able to make my code to work with UTL_SMTP package. Can some one guide me to change below code and make it work with UTL_SMTP method I created a mailing application which ...

Show Detail

APEX_MAIL.SEND function not working though its not giving any error

Have to send email from oracle apex using APEX_MAIL.SEND() method. I am using the code: BEGIN apex_mail.send(p_to => '[email protected]'/*l_to_addr*/, p_from =...

Show Detail

ACL error when trying to send mail via Oracle UTL_SMTP

I was trying to send an email via oracle utl_smtp, but every time i execute the apex_mail_p.mail procedure i get an ACL error, to be more precise it's the error ORA-24247. But i've created the acl,...

Show Detail

Force a APEX_MAIL to send a Date: message header?

In oracle apex, I am using APEX_MAIL.SEND function to send mail. The mail is sent correctly, however, automatically, another mail arrives with the following information: Your message WAS SUCCESSFU...

Show Detail

How to send mail in oracle apex

I tried to send a mail in oracle apex but I am not able to send because of this error ora-24247: network access denied by access control list (acl) in mail queue. The error is due to smtp server

Show Detail

Oracle APEX - Invalid lob when calling to APEX Apex_mail.send

I have a Oracle Database 18c Standard Edition 2 Release 18.0.0.0.0 server with Oracle apex 19 running on a Linux box. I am testing send emails with templates build on Apex. If I run the below code ...

Show Detail

cannot send emails with Oracle 11g APEX5

Trying to resolve an issue with sending emails using Oracle APEX5 11g. I've set up the administration settings as per Oracle instructions: SMTP Host Address - Defines the server address of the SMTP

Show Detail

How to send mail with an attachment to all users | Oracle APEX | UTL_SMTP method

It's been a hard time not able to get proper post where I can refer and develop the code. Need to follow only : UTL_SMTP method. This only works at my end Following is the way I have developed my

Show Detail

Oracle APEX_MAIL send to multiple recipients

What is the syntax for sending emails to multiple recipients with APEX_MAIL.SEND? The official page, https://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_mail.htm#AEAPI342, says; p_to Valid...

Show Detail

Debugging with Oracle's utl_smtp

A client of mine uses Oracle 9i's utl_smtp to send mails out notifications to managers when their employees have made travel requests and they woul like quite a few changes made to the mailouts don...

Show Detail