SQL Flow Field Guide

sp_send_dbmail

Check SQL Server version support in the source

Sends an e-mail message to the specified recipients.

What changes

Input
Not stated in the Microsoft summary.
Output or change
Sends an e-mail message to the specified recipients.

Syntax at a glance

dbo.sp_send_dbmail
    [ [ @profile_name = ] N'profile_name' ]
    [ , [ @recipients = ] 'recipients' ]
    [ , [ @copy_recipients = ] 'copy_recipients' ]
    [ , [ @blind_copy_recipients = ] 'blind_copy_recipients' ]
    [ , [ @subject = ] N'subject' ]
    [ , [ @body = ] N'body' ]
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @file_attachments = ] N'attachment [ ; ...n ]' ]
    [ , [ @query = ] N'query' ]
    [ , [ @execute_query_database = ] N'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] N'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 = ] query_result_no_padding ]
    [ , [ @mailitem_id = ] mailitem_id OUTPUT ]
    [ , [ @from_address = ] 'from_address' ]
    [ , [ @reply_to = ] 'reply_to' ]
[ ; ]

Work example

Sends an e-mail message to the specified recipients.

Write a proposed call on paper. Name the target, required permission, expected change, and recovery step before any lab use.

Check your work What can this procedure change or start, and what permission does it need?

Open Microsoft Learn for full syntax, permissions, and details for your version.