xp_sendmail to multiple recipients

  • I'm trying to send email to a group of people using the logic provided by following article:  http://www.sqlservercentral.com/columnists/kdas/xp_sendmail.asp

    However, I can only send out one email.  If I retrieved more than one email addresses, it won't work even though it shown "Mail Sent" multiple times.  What did I do wrong?

  • Post your code and maybe we can figure out what the problem is.

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • Here is my code:

    ########################################

    Declare @MyMessage nvarchar (255)

    Set @MyMessage = 'Sent out emails'

    Declare MyCursor Cursor For

    Select email From fs_users  Where user_id < 35

    Open MyCursor

    Fetch Next From MyCursor Into @MyRecipients

    While @@Fetch_Status = 0

    BEGIN

    Fetch Next From MyCursor Into @MyRecipients

    Exec Master.dbo.xp_sendmail @MyRecipients, @MyMessage

    End

    Close MyCursor

    Deallocate MyCursor

    ########################################

     

    Also, when I hard-coded multiple email addresses, it went out ok.

  • ....

    While @@Fetch_Status = 0

    BEGIN

    Exec Master.dbo.xp_sendmail @MyRecipients, @MyMessage

    Fetch Next From MyCursor Into @MyRecipients

    End

    ....

     

    Change the order

     


    * Noel

  • It works now. thanks. I'm happy now

Viewing 5 posts - 1 through 4 (of 4 total)

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