The system stored procedure sp_send_dbmail sends email messages. When this stored procedure is
executed, it inserts an row to the mail queue and records the Email message.
The queue insert operation triggers execution of the Database Mail process (DatabaseMail.exe). The
Database Mail process then reads the Email information and sends the message to the SMTP servers.
When the SMTP servers acknowledge or reject the message, the Database Mail process inserts a status
row into the status queue, including the result of the send attempt. This insert operation triggers the
execution of a system stored procedure that updates the status of the Email message send attempt.
Database Mail records all Email attachments in the system tables. SQL Server provides a set of system
views and stored procedures for troubleshooting and administration of the Database Mail queue.
Deprecated SQL Mail framework
The previous SQL Mail framework using xp_sendmail has been deprecated as of SQL Server 2008R2 in
accordance with https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms143729
(v=sql.105).
The legacy mail system has been completely replaced by the greatly enhanced DB mail framework
described here. The previous system has been out of use for many years because it was prone to syn-
chronous execution issues and windows mail profile quirks.
Syntax
EXECUTEsp_send_dbmail
[[,@profile_name =] '<Profile Name>']
[,[,@recipients =] '<Recipients>']
[,[,@copy_recipients =] '<CC Recipients>']
[,[,@blind_copy_recipients =] '<BCC Recipients>']
[,[,@from_address =] '<From Address>']
[,[,@reply_to =] '<Reply-to Address>']
[,[,@subject =] '<Subject>']
[,[,@body =] '<Message Body>']
[,[,@body_format =] '<Message Body Format>']
[,[,@importance =] '<Importance>']
[,[,@sensitivity =] '<Sensitivity>']
[,[,@file_attachments =] '<Attachments>']
[,[,@query =] '<SQL Query>']
[,[,@execute_query_database =] '<Execute Query Database>']
[,[,@attach_query_result_as_file =] <Attach Query Result as File>]
[,[,@query_attachment_filename =] <Query Attachment Filename>]
[,[,@query_result_header =] <Query Result Header>]
[,[,@query_result_width =] <Query Result Width>]
[,[,@query_result_separator =] '<Query Result Separator>']
[,[,@exclude_query_output =] <Exclude Query Output>]
[,[,@append_query_error =] <Append Query Error>]
[,[,@query_no_truncate =] <Query No Truncate>]
[,[,@query_result_no_padding =] @<Parameter for Query Result No Padding>]
[,[,@mailitem_id =] <Mail item id>] [,OUTPUT]
- 324 -