SQL Server provides extended stored procedures for sending and receiving messages through Exchange or Outlook, which are briefly described below.
First, start SQL Mail
Xp_startmail @user, @password
@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:
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
Read messages in your Inbox
xp_readmail [[@msg_id =] ' message_number '] [, [@type =] ' type ' [OUTPUT]]
[, [@peek =] ' peek ']
[, [@suppress_attach =] ' Suppress_attach ']
[, [@originator =] ' sender ' OUTPUT]
[, [@subject =] ' subject ' OUTPUT]
[, [@message =] ' message ' OUTPUT]
[, [@recipients =] ' recipients [;.. n] ' OUTPUT]
[, [@cc_list =] ' copy_recipients [;.. n] ' OUTPUT]
[, [@bcc_list =] ' blind_copy_recipients [;.. n] ' OUTPUT]
[, [@date_received =] ' Date ' OUTPUT]
[, [@unread =] ' Unread_value ' OUTPUT]
[, [@attachments =] ' attachments [;.. n] ' OUTPUT]
[, [@skip_bytes =] Bytes_to_skip OUTPUT]
[, [@msg_length =] Length_in_bytes OUTPUT]
[, [@originator_address =] ' sender_address ' OUTPUT]]
Parameter description:
Parameter description
@originator Sender
@subject topics
@message Information
@recipients Recipients
@skip_tytes the number of bytes skipped when reading message information, used to get message segments sequentially.
@msg_length determine the length of all information, usually with @skip_bytes to process long information
V. Sequential processing of the next message
xp_findnextmsg [[@msg_id =] ' message_number ' [OUTPUT]]
[, [@type =] type]
[, [@unread_only =] ' unread_value '])
VI. Delete Mail
xp_deletemail {' Message_number '}
Delete all messages in the Inbox if you do not specify a message number
Seven, automatically processing mail
sp_processmail [[@subject =] ' subject ']
[, [@filetype =] ' filetype ']
[, [@separator =] ' separator ']
[, [@set_user =] ' user ']
[, [@dbuse =] ' dbname ']