Email from condition

  • I have a list of email address. Previously I use sp_send_dbmail and adhoc doing it one by one. The list is getting longer.

    Any suggestion how can I send email from condition?

    Example:

    Code emailaddress

    A a@abc.com

    B b@abc.com

    C c@abc.com

    case when code='A' then send it to a@abc.com

    case when code='B' then send it to b@abc.com

    Is this possible?

    Or I still need to do one by one?

  • You need to call sp_send_dbmail once for every email you want to send.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • There are no other way?

    As the list are growing.. Feel like not efficient doing it one by one.

  • Calling the proc once for each email is the supported way. If you need bulk mailer capabilities and performance then Database Mail might not be right for you.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • I have like 1000 recipients. I need to do that 1000 times?

    Any idea how can I solve this?

  • 1000 is actually not much at all. Yes, again, you need to call the proc 1000 times to send a separate email to eaxh recipient. Do you have the emails stored in a table? Writing code to call the proc once for each email is not too difficult.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Is it the exact same message (unpersonalised) that you want to send to each recipient. You can send the same message to multiple recipients, so why not build the list first and then pass it to the @recipients parameter?

    John

  • Same store proc but different parameter. Results send to different recipients.

    exec store proc A 'henry','getdate()'

    send to henry@gmail.com

    exec store proc B 'george','getdate()'

    send to george@gmail.com

    Doing this 1000 times? Any suggestion and guidance.

  • http://stackoverflow.com/questions/886293/how-do-i-execute-a-stored-procedure-once-for-each-row-returned-by-query

    Typically looping and cursors are to be avoided but in cases where you must call a procedure once for each row for a relatively small number of rows it is warranted.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply