Small Examples of Working with Database Mail Queue in MSSQL
Stopping Database Mail
exec msdb.dbo.sysmail_stop_sp
Cleaning the history of undelivered messages
-- If the number of records in the msdb.sysmail_allitems table is very large,
-- then use the @sent_before parameter to limit the deleted records
-- then use the @sent_before parameter to limit the deleted records
exec msdb.dbo.sysmail_delete_mailitems_sp @sent_status = \'unsent\'
exec msdb.dbo.sysmail_delete_mailitems_sp @sent_status = \'retrying\'
exec msdb.dbo.sysmail_delete_mailitems_sp @sent_status = \'failed\'
Viewing the message queue
select * from msdb..sysmail_allitems
where sent_status <> \'sent\'
order by mailitem_id desc
Stopping and starting Database Mail
exec msdb.dbo.sysmail_stop_sp
exec msdb.dbo.sysmail_start_sp
Checking the current status of the Database Mail service
exec msdb..sysmail_help_queue_sp
Viewing the event logs of the Database Mail service
select * from msdb..sysmail_event_log order by log_id desc
Comments (0)
No comments yet.