Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    17

    Unanswered: Database Mail Configuration

    All,

    I need some help in sending email in SQL Server...

    I have configured database mail and able to send mails through "EXEC msdb.dbo.sp_send_dbmail" but I need to include logic and send mail based on success or failure of a stored procedure....

    example

    I execute a stored procedure like this

    Osql.exe -E -Q "exec proc_name"

    immediately after this based on success or failure of the above SP (capturing correct values and status from the above) i need to execute

    EXEC msdb.dbo.sp_send_dbmail with message "completed successfully"

    if failure

    EXEC msdb.dbo.sp_send_dbmail "please check failures"

    Please help

    Thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You didn't specif SQL Server version, so I'll assume 2005 onwards
    Code:
    BEGIN TRY
      EXEC dbo.some_proc
      EXEC master..sp_send_dbmail "wahooo"
    END TRY
    BEGIN CATCH
      EXEC master..sp_send_dbmail "oh no!"
    END CATCH
    P.S. this is pseudo code
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •