This discussion is archived
2 Replies Latest reply: Oct 11, 2013 4:57 AM by AjithPathiyil RSS

Sending Email

raghav1212 Newbie
Currently Being Moderated

Hi ,

 

I am using apex 4.0.2 i have a requirement of sending email through the apex application can any body suggest me how i can proceed.

 

Thanks

Raghav

  • 1. Re: Sending Email
    jariola Guru
    Currently Being Moderated

    Hi,

     

    Maybe you check documentation

    APEX_MAIL

     

    Also check Learning Library

    OLL Advanced Search

     

    Regards,

    Jari

  • 2. Re: Sending Email
    AjithPathiyil Newbie
    Currently Being Moderated

    Hi Raghav,

     

    Please find a sample code which helps you sending a email using HTMLDB_MAIL.SEND API. This is a working code, and you can change it for your own use. and please do not forget to mark this as working after you try that

     

    create or replace PROCEDURE user_send_message(p_title varchar2, p_email varchar2,

          p_text1 varchar2 default null, p_replace1 varchar2 default null,

          p_text2 varchar2 default null, p_replace2 varchar2 default null,

          p_text3 varchar2 default null, p_replace3 varchar2 default null,

          p_text4 varchar2 default null, p_replace4 varchar2 default null,

          p_text5 varchar2 default null, p_replace5 varchar2 default null,

          p_text6 varchar2 default null, p_replace6 varchar2 default null,

          p_text7 varchar2 default null, p_replace7 varchar2 default null) AS

       v_subject varchar2(4000);

       v_message varchar2(4000);

       v_admin_email varchar2(4000);

       v_system varchar2(100); -- get system name to use in subject

       BEGIN

         select message, subject

         into v_message, v_subject

         from user_messages

         where title=p_title;

        

         select message into v_admin_email

         from user_messages

         where title='ADMIN_EMAIL';

        

         -- add in system name to subject if requested

         select message into v_system

         from user_messages

         where title='SYSTEM';

         v_subject:=replace(v_subject,'#SYSTEM#',v_system);

        

         -- merge other requested portions

         v_message:=user_message_merge(v_message);

         

         if (p_text1 is not null) then

             v_message:=replace(v_message,p_text1,p_replace1);

         end if;   

         if (p_text2 is not null) then

             v_message:=replace(v_message,p_text2,p_replace2);

         end if;  

         if (p_text3 is not null) then

               v_message:=replace(v_message,p_text3,p_replace3);

         end if;

         if (p_text4 is not null) then

               v_message:=replace(v_message,p_text4,p_replace4);

         end if;

         if (p_text5 is not null) then

               v_message:=replace(v_message,p_text5,p_replace5);

         end if;

         if (p_text6 is not null) then

                v_message:=replace(v_message,p_text6,p_replace6);

         end if;

         if (p_text7 is not null) then

                 v_message:=replace(v_message,p_text7,p_replace7);

         end if;

        

         -- merge other requested portions, 2nd followup to complete items

         v_message:=user_message_merge(v_message);

        

         HTMLDB_MAIL.SEND(

           P_TO        => p_email,

           P_FROM      => v_admin_email,

           P_BODY      => v_message,

           P_BODY_HTML => NULL,

           P_SUBJ      => v_subject);

         EXCEPTION

               WHEN OTHERS THEN

                 RAISE_APPLICATION_ERROR(-20100, 'Error sending message '||p_title);

    END;

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points