Mail user send 10 times to the CC, I need to mail send only once to CC. Loop problem

Dear Sir.

In my application, I created a survey then it goes to HOD HOD assign to the group or Indivitual User.if HOD assign inquiry to ressemelable it to the group. Then send Mail to all users in the Group and send mail to the user who who after investigation.

Suppose that the Group has 10 users.
But now my problem is when I select the group then mail send to the group users (10) but 10 send mail to users that query.i Post uses CC who has the Post request.

I don't need that once mail send to the user who posts this request nothing 10 times.

It's looped .loop is fire 10 times for the CC, I need fire once for CC.



How can I do that.

My Code is.
DECLARE

l_id number;
to_add varchar2(1000);
to_sub_by varchar2(1000);
from_add varchar2(1000);
l_body varchar2(4000):=:P33_DESCRIPTION;
l_sub varchar2(1000):=:P33_SUBJECT;
I_case varchar2(10):=:P33_CASE_ID;
I_isue_dte date:=:P33_SUBMITTED_ON;
l_regd    varchar(100);


CURSOR C1 IS SELECT EMAIL_ID,(SELECT EMAIL_ID FROM USER_MAS WHERE USER_ID =:P33_SUBMITTED_BY_ID) AS D FROM USER_MAS WHERE USER_GR_ID=:P33_ASSIGNED_TO_GROUP_ID AND USER_ID NOT IN(:APP_USER);



BEGIN

if :P33_ASSIGNED_TO_GROUP_ID is not null then

open C1;
LOOP
FETCH C1 INTO to_add,to_sub_by;
EXIT WHEN C1%NOTFOUND;

select email_id,user_name into from_add,l_regd from user_mas where user_id=:app_user;

l_id:=APEX_MAIL.SEND(
        p_to        => to_add, -- change to your email address
        P_cc        => to_sub_by, 
        p_from      => from_add,
        p_body      => 'Issue Information'||''||chr(13)||chr(10)||chr(13)||chr(10)||
                       'www.farhorizonindia.net:7777/crm'||''||chr(13)||
                       'Issue Title'||':'||l_sub||CHR(13)||chr(10)||
                       'Issue Number'||':'||I_case||CHR(13)||
                       'Issue Open Date'||':'||I_isue_dte||''||chr(13)||chr(10)||CHR(13)||chr(10)||
                       'Most Recent Comment'||':'||''||chr(13)||chr(10)||
                       l_body||chr(13)||chr(10)||''||CHR(13)||chr(10)||'Regards'||chr(13)||chr(10)||''||l_regd||CHR(13)||chr(10)||CHR(13)||chr(10)||'Please do not reply to this email.If you wish to update the call.please login to the issue Management.',
      
  P_subj      => I_case ||' Issue '||l_sub);

end loop;
close C1;

end if;

COMMIT;
apex_mail.push_queue(
P_SMTP_HOSTNAME => '102.111.0.9',
P_SMTP_PORTNO => 25);

commit;

END;
How to solve it.

Thank you

Published by: Sophie on June 22, 2011 05:17

Published by: Sophie on June 22, 2011 20:57

Published by: Sophie on June 22, 2011 22:52

Published by: Sophie on June 23, 2011 12:11 AM

Published by: Sophie on June 23, 2011 01:15

Hello

Maybe like this:

DECLARE
 l_id number;
 to_add varchar2(1000);
 to_sub_by varchar2(1000);
 from_add varchar2(1000);
 l_body varchar2(4000):=:P33_DESCRIPTION;
 l_sub varchar2(1000):=:P33_SUBJECT;
 I_case varchar2(10):=:P33_CASE_ID;
 I_isue_dte date:=:P33_SUBMITTED_ON;
 l_regd    varchar(100);

  CURSOR C1 IS SELECT EMAIL_ID FROM USER_MAS WHERE USER_GR_ID=:P33_ASSIGNED_TO_GROUP_ID AND USER_ID NOT IN(:APP_USER);

  BEGIN
     if :P33_ASSIGNED_TO_GROUP_ID is not null
     then
       -- do this query once!
       select email_id,user_name into from_add,l_regd from user_mas where user_id=:app_user;
        -- first send a mail for the CC email
        SELECT EMAIL_ID into to_sub_by FROM USER_MAS WHERE USER_ID =:P33_SUBMITTED_BY_ID;
        --email
        l_id:=APEX_MAIL.SEND(
        p_to        => to_sub_by, -- only the cc email
        p_from      => from_add,
        p_body      => 'Issue Information'||''||chr(13)||chr(10)||chr(13)||chr(10)||
                       'www.farhorizonindia.net:7777/crm'||''||chr(13)||
                       'Issue Title'||':'||l_sub||CHR(13)||chr(10)||
                       'Issue Number'||':'||I_case||CHR(13)||
                       'Issue Open Date'||':'||I_isue_dte||''||chr(13)||chr(10)||CHR(13)||chr(10)||
                       'Most Recent Comment'||':'||''||chr(13)||chr(10)||
                       l_body||chr(13)||chr(10)||''||CHR(13)||chr(10)||'Regards'||chr(13)||chr(10)||''||l_regd||CHR(13)||chr(10)||CHR(13)||chr(10)||'Please do not reply to this email.If you wish to update the call.please login to the issue Management.',

  P_subj      => I_case ||' Issue '||l_sub);

-- Now the loop throught the users from the group
  open C1;
  LOOP
     FETCH C1 INTO to_add;
     EXIT WHEN C1%NOTFOUND;

l_id:=APEX_MAIL.SEND(
        p_to        => to_add, -- change to your email address
--        P_cc        => to_sub_by,  -- no more CC
        p_from      => from_add,
        p_body      => 'Issue Information'||''||chr(13)||chr(10)||chr(13)||chr(10)||
                       'www.farhorizonindia.net:7777/crm'||''||chr(13)||
                       'Issue Title'||':'||l_sub||CHR(13)||chr(10)||
                       'Issue Number'||':'||I_case||CHR(13)||
                       'Issue Open Date'||':'||I_isue_dte||''||chr(13)||chr(10)||CHR(13)||chr(10)||
                       'Most Recent Comment'||':'||''||chr(13)||chr(10)||
                       l_body||chr(13)||chr(10)||''||CHR(13)||chr(10)||'Regards'||chr(13)||chr(10)||''||l_regd||CHR(13)||chr(10)||CHR(13)||chr(10)||'Please do not reply to this email.If you wish to update the call.please login to the issue Management.',

  P_subj      => I_case ||' Issue '||l_sub);

end loop;
close C1;

end if;

COMMIT;
apex_mail.push_queue(
P_SMTP_HOSTNAME => '102.111.0.9',
P_SMTP_PORTNO => 25);

commit;

END;

Herald tiomela
http://htendam.WordPress.com

Tags: Database

Similar Questions

Maybe you are looking for