sysmail_mailattachments (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 attachment submitted to Database Mail. Use this view when you want information about Database Mail attachments. To review all e-mails processed by Database Mail use sysmail_allitems (Transact-SQL).

Column nameData typeDescription
attachment_idintIdentifier of the attachment.
mailitem_idintIdentifier of the mail item that contained the attachment.
filenamenvarchar(520)The file name of the attachment. When attach_query_result is 1 and query_attachment_filename is NULL, Database Mail creates an arbitrary filename.
filesizeintThe size of the attachment in bytes.
attachmentvarbinary(max)The content of the attachment.
last_mod_datedatetimeThe date and time of the last modification of the row.
last_mod_usersysnameThe user who last modified the row.

When troubleshooting Database Mail, use this view to see the properties of the attachments.

Attachments stored in the system tables can cause the msdb database to grow. Use sysmail_delete_mailitems_sp to delete mail items and their associated attachments. For more information, see Create a SQL Server Agent Job to Archive Database Mail Messages and Event Logs.

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

sysmail_allitems (Transact-SQL)
sysmail_faileditems (Transact-SQL)
sysmail_sentitems (Transact-SQL)
sysmail_unsentitems (Transact-SQL)
sysmail_event_log (Transact-SQL)

Community Additions