How to use SQL Mail to send and receive and automate mail processing

Source: Internet
Author: User
Tags how to use sql
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 ']



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.