xp_deletemail (Transact-SQL)
Deletes a message from the Microsoft SQL Server inbox. This procedure is used by sp_processmail to process mail in the SQL Server inbox.
Note
This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
Syntax
xp_deletemail { 'message_id' }
Arguments
- 'message_id'
Is the proprietary message number (assigned by xp_findnextmsg) of the mail message in the inbox that should be deleted. message_id is varchar(255), with no default.
Return Code Values
0 (success) or 1 (failure)
Result Sets
xp_deletemail returns a message when passed a valid message ID.
Remarks
Any failure except an invalid parameter is logged to the Windows application log.
xp_deletemail deletes the message from the inbox, but does not delete any attachments from the file system. You must delete attachments manually. You can suppress the generation of attachments by setting the suppress_attach parameter for xp_readmail to TRUE. For more information about security issues with attachments, see xp_readmail (Transact-SQL).
xp_deletemail does not keep a log of deleted messages or users who deleted the messages. This may cause auditing problems in an environment where several users have permission to execute xp_deletemail. To minimize this problem, limit permissions for xp_deletemail to members of the sysadmin fixed server role.
Permissions
Requires membership in the sysadmin fixed server role, but EXECUTE permissions can granted to other users. However, for security reasons, we recommend that permissions for this stored procedure be limited to members of the sysadmin fixed server role.
Examples
The following example retrieves a message ID supplied from xp_findnextmsg, and then uses that message ID to delete a message. The value from xp_findnextmsg is placed in the local variable @message_id.
DECLARE @message_id varchar(255) ;
USE master ;
EXEC xp_findnextmsg @msg_id = @message_id OUTPUT ;
EXEC xp_deletemail @message_id ;