JB999
JB999

Reputation: 507

Oracle Apex - Send Email from a list

I have a table with a list of several different emails and Items. I'm trying to send out an email (whenever a button is pressed) to all of those emails with their Items, e.g.:

table example

An email like this should be send when the button is pressed:

"Dear [email protected], your cart is ready with item 1 and item 2."

I know how to send emails using Apex Items but I'm lost on how to do it with information inside a table. Does anyone know how to do that?

Thanks!

Upvotes: 1

Views: 409

Answers (1)

Littlefoot
Littlefoot

Reputation: 143083

This might be one option: create a procedure which runs when button is pressed; it reads table contents and "aggregates" list of items into message text.

As you already know how to send mail, I hope this is enough for you to make it work.

SQL> with test (user_email, item) as
  2    -- sample data
  3    (select '[email protected]', 'item 1' from dual union all
  4     select '[email protected]', 'item 2' from dual union all
  5     --
  6     select '[email protected]', 'item 1' from dual union all
  7     select '[email protected]', 'item 2' from dual union all
  8     select '[email protected]', 'item 3' from dual
  9    )
 10  -- code you might be interested in
 11  select user_email,
 12    'Dear ' || user_email ||', your cart is ready with ' ||
 13    listagg(item, ', ') within group (order by item) as message_text
 14  from test
 15  group by user_email
 16  /

USER_EMAIL   MESSAGE_TEXT
------------ ----------------------------------------------------------------------
[email protected] Dear [email protected], your cart is ready with item 1, item 2, item 3
[email protected] Dear [email protected], your cart is ready with item 1, item 2

SQL>

Upvotes: 3

Related Questions