sysmail_stop_sp (Transact-SQL)

Applies to: SQL Server

Stops Database Mail by stopping the Service Broker objects that the external program uses.

Transact-SQL syntax conventions

Syntax

sysmail_stop_sp
[ ; ]

Arguments

None.

Return code values

0 (success) or 1 (failure).

Remarks

This stored procedure is in the msdb database.

sysmail_stop_sp stops the Database Mail queue that holds outgoing message requests and turns off Service Broker activation for the external program.

When the queues are stopped, the Database Mail external program doesn't process messages. This stored procedure allows you to stop Database Mail for troubleshooting or maintenance purposes.

To start Database Mail, use sysmail_start_sp. Notice that sp_send_dbmail still accepts mail when the Service Broker objects are stopped.

Note

sysmail_stop_sp only stops the queues for Database Mail. This stored procedure does not deactivate Service Broker message delivery in the database. This stored procedure does not disable the Database Mail extended stored procedures to reduce the surface area. To disable the extended stored procedures, see the Database Mail XPs option of the sp_configure system stored procedure.

Permissions

This stored procedure is owned by the db_owner role. You can grant EXECUTE permissions for any user, but these permissions may be overridden during a SQL Server upgrade.

Examples

The following example shows stopping Database Mail in the msdb database. The example assumes that Database Mail has been enabled.

USE msdb;
GO

EXECUTE dbo.sysmail_stop_sp;
GO