xp_smtp_sendmail

  • so i have select @email = (blablabla)

    which gives me back emails as

    mail1@mail.com

    mail2@mail.com

    etc...

    when i send it out like:

    exec @rc = master.dbo.xp_smtp_sendmail

        @FROM   = N'myemail@mail.com',

        @FROM_NAME  = N'From Me,

        @TO   = @Email,

        @subject  = N'Test',

        @message  = @Body,

        @type   = N'text/html',

        @server   = @EmailServer

       select RC = @rc

    @TO of course expects one email...  so how do I go around that when I have @email giving me back 2+ emails? Maybe build a comma-separated string of those emails? ANy help is appreciated.

  • Yes, xp_smtp_sendmail accepts multiple recipients using comma as separator. So do something like:

    SELECT @email = COALESCE(@email, '') + emailaddresscolumn + ','

    FROM sometable

    SET @email = LEFT(@email, LEN(@email) - 1)

    exec @rc = master.dbo.xp_smtp_sendmail

    @FROM = N'myemail@mail.com',

    @FROM_NAME = N'From Me,

    @TO = @Email,

    @subject = N'Test',

    @message = @Body,

    @type = N'text/html',

    @server = @EmailServer

    select RC = @rc

Viewing 2 posts - 1 through 1 (of 1 total)

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