SQL Server provides extended stored procedures for sending and receiving messages through Exchange or Outlook, which are briefly described below.
First, start SQL Mail
@user and @password are optional.
You can also open support Services in Enterprise Manager, right-click on SQL Mail, open the right-click menu, and press start to start
Second, stop SQL Mail
Xp_stopmail
You can also use the stop in the menu in the above method to stop
Third, send mail
xp_sendmail {[@recipients =] 'recipients [;...n]'}
[,[@message =] 'message>
[,[@query =] 'query>
[,[@attachments =] attachments]
[,[@copy_recipients =] 'copy_recipients [;...n]'
[,[@blind_copy_recipients =] 'blind_copy_recipients [;...n]'
[,[@subject =] 'subject>
[,[@type =] 'type>
[,[@attach_results =] 'attach_value>
[,[@no_output =] 'output_value>
[,[@no_header =] 'header_value>
[,[@width =] width]
[,[@separator =] 'separator>
[,[@echo_error =] 'echo_value>
[,[@set_user =] 'user>
[,[@dbuse =] 'database>
Where the @recipients is required
Parameter description:
@recipients recipients, separated by commas in the middle
@message the information to send
@query determine a valid query that executes and attaches to the message, which can refer to any object except the Insert table and the Delete table in the trigger
@attachments Accessories
@copy_recipients cc
@blind_copy_recipients Secret Delivery
@subject Title
@attach_results Specify the results of the query to be sent as an attachment
@no_header column names that do not send query results
@set_user the user name for the query join, default to Guset
@dbuse the database used by the query, default is the default database