Checking sp_send_email permission before executing
In my stored procedure, I send emails with sp\_send_email. My stored procedure will be run in different environments; some will have emailing enabled, some won't.

If I run sp\_send_email without it being enabled, I (quite rightly) get this error message

> SQL Server blocked access to procedure 'dbo.sp\_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server.

I want to check whether emailing is enabled first, so I can avoid the error by doing the following:

    IF @is_enabled
    BEGIN
        EXEC sp_send_email ...
    END

How do I correctly set @is\_enabled?

Checking sp_send_email permission before executing
===

In my stored procedure, I send emails with sp\_send_email. My stored procedure will be run in different environments; some will have emailing enabled, some won't.

If I run sp\_send_email without it being enabled, I (quite rightly) get this error message

> SQL Server blocked access to procedure 'dbo.sp\_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server.

I want to check whether emailing is enabled first, so I can avoid the error by doing the following:

    IF @is_enabled
    BEGIN
        EXEC sp_send_email ...
    END

How do I correctly set @is\_enabled?
