Database Mail Log and Audits


Applies To: SQL Server 2016

The Database Mail logging functionality is designed to provide a way to isolate and correct problems. Database Mail stores the log information in the msdb database. Information about Database Mail e-mail content, status of e-mails, and any messages received, such as errors are logged by Database Mail and can be used for troubleshooting and auditing purposes.

Tables in the msdb database log information from the Database Mail External Program. Database Mail Views (Transact-SQL) expose the tables for troubleshooting purposes. Errors appear in the sysmail_event_log (Transact-SQL) view if Service Broker cannot activate the external program, if the external program encounters networking errors or if the Simple Mail Transport Protocol (SMTP) server refuses an e-mail message. In the event that the external program cannot log to the msdb tables, the program logs errors to the Windows application event log.

Internal tables in the msdb database contain the e-mail messages and attachments sent from Database Mail, together with the current status of each message. Database Mail updates these tables as each message is processed.

Reviewing and managing Database Mail logsLink to Topic
Check the delivery status of an individual messageCheck the Status of E-Mail Messages Sent With Database Mail
Clean up Database Mail messages, attachments, and log entriessysmail_delete_mailitems_sp (Transact-SQL)

 sysmail_delete_log_sp (Transact-SQL)
Archive the Database Email Messages and LogsCreate a SQL Server Agent Job to Archive Database Mail Messages and Event Logs

Monitor Resource Usage (System Monitor)

Community Additions