Sql-server – Configure sp_send_dbmail to send emails ONLY to certain recipients

sql server

For our environment test we need to configure sp_send_dbmail to send emails only to certain recipients. Let's say a stored procedure executes the following code:

EXEC msdb.dbo.sp_send_dbmail
    @recipients='developer@myorganization.com'; 'realuser@myorganization.com',
    @body = @myBody,
    @subject = @mySubject,
    @profile_name =@myProfileName

I need the email to be sent only to developer@myorganization.com, and not to realuser@myorganization.com. Is there a way that i can configure this?
Changing realusers email address won't do it for me.

Best Answer

There is nothing built in that you could use already.

I would suggest creating a "wrapper" stored procedure for sp_send_dbmail, that accepts the exact same parameters and passes them through, with additional logic in place to check the @ recipients parameter that is passed against your exclusion list.