xp_findnextmsg Extended Stored Procedure

Accepts a message ID for input and returns the message ID for output. This extended stored procedure is used with the sp_processmail system stored procedure in order to process mail in the SQL Server inbox.

Syntax

xp_findnextmsg [@msg_id = msg_id [OUTPUT]]
    [, @type = type]
    [, @unread_only = {'true' | 'false'}])

where

@msg_id = msg_id
Is an input and output parameter; specifies the string of the message on input and the string of the next message on output.
OUTPUT
When specified, places the value of the msg_id in the output parameter. When not specified, the msg_id is returned as a single-column, single-row results set.
@type = type
Is the input message type based on the MAPI mail definition:
IP[M | C].Vendorname.subclass

Message types beginning with IPM will appear in the inbox of the mail client, and will be found or read by xp_findnextmsg if the @type is NULL. Message types beginning with IPC do not appear in the inbox of the mail client and must be found or read by setting the @type parameter. The default is NULL.

@unread_only = 'true' | 'false'
Specifies that only unread messages are considered. The default is true.

Remarks

This extended stored procedure returns a successful (0) or failed (1) status. Any failure except an invalid parameter is logged to the Windows NT application event log.

Example

This example returns the status when searching for the next message ID (for only unread messages). In this example, the value from xp_findnextmsg is placed in a local variable named @message_id.

EXEC @status = xp_findnextmsg @msg_id = @message_id OUTPUT

Permission

Execute permission defaults to the system administrator, who can grant permission to other users.

See Also

sp_processmail xp_sendmail
xp_deletemail xp_startmail
xp_readmail xp_stopmail