Database Mail: sending to multiple recipients from tables

  • I am using database mail to send emails to our Lotus Notes SMTP server using sp_send_dbmail. I want to accomplish the following.

    I have maintained department-wise users email address in one table .  Now I want to send mail to one particular department and there can be 1-15 users as recipient for that mail.  How can I do that using sp_send_dbmail?

  • You have to generate the ';' seperated list ...here is example...

    declare

    @i varchar(1000)

    select

    @i = ''

    select

    @i = @i+';'+name from sysobjects where id <10

    select

    @i

    MohammedU
    Microsoft SQL Server MVP

  • DECLARE @email VARCHAR(4000)

    SET @email = ''

    SELECT @email = RTRIM(@email) + RTRIM(email) + ';'

    FROM Users

    WHERE email <> '' AND DepCode = 'A'

    execute sp_send_dbmail --

    --setting @recipient to @email

    @recipient = @email

    Thanx for help

  • You got it..

    If your email id datatype is varchar then you don't need to use RTRIM function...

     

    MohammedU
    Microsoft SQL Server MVP

  • I went for an interview today and they explaind their current issue with sql2005 as a problem getting sql2005 to mail their lotus notes users. I suggested xp sendmail with a caveat it may not support 2005.

    But i would be interested how to set up win 2003 to use sp_send_dbmail im presming the outlook client is still required?

     

    Cheers

  • There is no longer a need for an email client when using sp_send_dbmail with SQL Server 2005.  There is also a way to use the CDO object in SQL 2000 that eliminates the email client as well.  Let me know and I'll send you a stored proc for that one.

     

     

    Marvin Dillard
    Senior Consultant
    Claraview Inc

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

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