Send Mail task

  • I have to send the error message to the mail which i gave in Send mail task. How can i store the error message in the variable, so that i can pass the variable to the send mail task. can u please help me in this.. Your help would be appreciated.. Thank you in adavnce

  • Please post the the code you have so far...

    Off hand you could try something like:DECLARE @ErrNo int, @ErrMsg nvarchar(256), @Recipients nvarchar(256), @EmailSubjectLine nvarchar(256), @Subject nvarchar(256)

    BEGIN TRY

    --Do something here...

    END TRY

    BEGIN CATCH

    SELECT @ErrNo = ERROR_NUMBER(), @ErrMsg = ERROR_MESSAGE()

    SET @Subject = 'Email Could not be sent :: ' + @EmailSubjectLine

    SET @ErrMsg = 'ERROR :: ' + @ErrNo + CHAR(13) + CHAR(13)

    + '----------------------------------------------------------' + CHAR(13) + CHAR(13)

    + @ErrMsg

    + '----------------------------------------------------------' + CHAR(13) + CHAR(13)

    + 'Subject: ' + @EmailSubjectLine + CHAR(13)

    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'me@mymail.com',

    @subject = @Subject,

    @body = @ErrMsg,

    @body_format = 'HTML',

    @importance = 'High'

    END CATCH

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

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

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