sysmail_allitems (Transact-SQL)

 

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Contains one row for each message processed by Database Mail. Use this view when you want to see the status of all messages.

To see only messages with the failed status, use sysmail_faileditems (Transact-SQL). To see only unsent messages, use sysmail_unsentitems (Transact-SQL). To see only messages that were sent, use sysmail_sentitems (Transact-SQL).

Applies to: SQL Server (SQL Server 2008 through current version).
Column nameData typeDescription
mailitem_idintIdentifier of the mail item in the mail queue.
profile_idintThe identifier of the profile used to send the message.
recipientsvarchar(max)The e-mail addresses of the message recipients.
copy_recipientsvarchar(max)The e-mail addresses of those who receive copies of the message.
blind_copy_recipientsvarchar(max)The e-mail addresses of those who receive copies of the message but whose names do not appear in the message header.
subjectnvarchar(510)The subject line of the message.
bodyvarchar(max)The body of the message.
body_formatvarchar(20)The body format of the message. The possible values are TEXT and HTML.
importancevarchar(6)The importance parameter of the message.
sensitivityvarchar(12)The sensitivity parameter of the message.
file_attachmentsvarchar(max)A semicolon-delimited list of file names attached to the e-mail message.
attachment_encodingvarchar(20)The type of mail attachment.
queryvarchar(max)The query executed by the mail program.
execute_query_databasesysnameThe database context within which the mail program executed the query.
attach_query_result_as_filebitWhen the value is 0, the query results were included in the body of the e-mail message, after the contents of the body. When the value is 1, the results were returned as an attachment.
query_result_headerbitWhen the value is 1, query results contained column headers. When the value is 0, query results did not include column headers.
query_result_widthintThe query_result_width parameter of the message.
query_result_separatorchar(1)The character used to separate columns in the query output.
exclude_query_outputbitThe exclude_query_output parameter of the message. For more information, see sp_send_dbmail (Transact-SQL).
append_query_errorbitThe append_query_error parameter of the message. 0 indicates that Database Mail should not send the e-mail message if there is an error in the query.
send_request_datedatetimeThe date and time the message was placed on the mail queue.
send_request_usersysnameThe user who submitted the message. This is the user context of the database mail procedure, not the From: field of the message.
sent_account_idintThe identifier of the Database Mail account used to send the message.
sent_statusvarchar(8)The status of the mail. Possible values are:

 sent - The mail was sent.

 unsent - Database mail is still attempting to send the message.

 retrying - Database Mail failed to send the message but is attempting to send it again.

 failed - Database mail was unable to send the message.
sent_datedatetimeThe date and time that the message was sent.
last_mod_datedatetimeThe date and time of the last modification of the row.
last_mod_usersysnameThe user who last modified the row.

Use the sysmail_allitems view to see the status of all messages processed by Database Mail. When troubleshooting Database Mail, this view may help you identify the nature of the problem, by showing you the attributes of the messages that were sent compared with the attributes of the messages that were not sent.

The system tables exposed by this view contain all messages and may cause the msdb database to grow. Delete old messages from the view periodically to reduce the size of the tables. For more information, see Create a SQL Server Agent Job to Archive Database Mail Messages and Event Logs.

Granted to sysadmin fixed server role and DatabaseMailUserRole database role. When executed by a member of the sysadmin fixed server role, this view shows all messages. All other users only see the messages that they submitted.

Community Additions

ADD
Show: