I need to log the error message if SQL Server failed to send its DB Mail. All the DB Configuration is done and email is also working fine. In case if any error, how can I get the error message from msdb.dbo.sp_send_dbmail?
Asked
Active
Viewed 983 times
1 Answers
0
The same way you capture any other tsql error - you wrap it in a try/catch block and "handle" the error however you want. In addition, you also need to check the value returned by the stored procedure. Note that sql server doesn't actually send the email - that is the responsibility of the smtp server.
And now is a good time to read the documentation and learn about the available features. There is a procedure to check the status of any email.

SMor
- 2,830
- 4
- 11
- 14