Search
Home
Articles
Backup
Books
Certification
FAQ
Products
Replication
Scripts
Seminars
Training
TSQL

MSDN Fourms
Philippine SSUG
Fort Worth SSUG
Oklahoma City SSDG

Resume

MHS Enterprises
BlowFrog Software
FilAm Software
AcrylicAcetate.com
Bargain Humidors
Western Humidor

Configuring and Managing SQL Mail 1 2 3 4 5 6 7

Using XP_FindNextMSG

FindNextMSG lets you move through the inbox, seeing the messages that are available. It has an Unread_ONLY flag that you can set, making it easier to process only pending messages, leaving others in the inbox.

xp_findnextmsg [[@msg_id =] 'message_number' [OUTPUT]]
[,[@type =] type]
[,[@unread_only =] 'unread_value'])

The parameters are outlined below:

Parameter Description
@msg_id ID of the next message
@unread_only Restricts the search to only unread messages.

Using XP_ReadMail

When you’ve found the message you want to read, you can use the ReadMail stored procedure to pull in the contents and control how it is processed. There are a number of parameters to this call, each controlling different aspects of how the message is provided to the SQL process. The syntax is shown below, the parameters are outlined in the table following the listing.

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
@msg_id ID of the next message
@originator The returned email address of the user sending the message. It can only be 255 characters.
@subject The subject of the message. Can only be 255 characters.
@message This is the text of the mail message which is normally a query to execute. This variable is only capable of handling 8000 characters.
@recipients This is a semicolon separated list of recipients
@skip_bytes This is a hold over from version 6.5 which was used to read large messages in chunks. It specifies the number of bytes to skip when reading the mail message.
@msg_length Used in conjunction with @skip_bytes to sequentially process 255 byte chunks of a message.

Configuring and Managing SQL Mail 1 2 3 4 5 6 7

Michael R. Hotek

All content on this site, except where noted, represents an original work of Michael R. Hotek and is protected by applicable copyright laws. The SQL Server FAQ is the sole work of Neil Pike. No page, portion of a page, or download may be used for commercial purposes in whole or in part without the express, written permission of the applicable author.