How to remove in sp_send db mail

sp_send_dbmail is a stored procedure in SQL Server that sends an email message using the Database Mail feature. If you want to remove a sent email message, you can use the sp_delete_dbmail stored procedure.

Here are the steps to remove a sent email message using sp_delete_dbmail:

  1. Open a new query window in SQL Server Management Studio (SSMS) or use the sqlcmd command-line tool.
  2. Execute the following command to delete the email message:
    EXEC sp_delete_dbmail @message_id = <message_id>

    Replace <message_id> with the actual message ID of the email message you want to delete. You can find the message ID in the msdb.dbo.sysmail_allitems system table.

For example:

EXEC sp_delete_dbmail @message_id = 12345

This will delete the email message with the message ID 12345.

Note: Make sure you have the necessary permissions to delete email messages. The sp_delete_dbmail stored procedure requires the db_owner or db_datareader role.

Alternatively, you can use the msdb.dbo.sp_delete_dbmail stored procedure with the @message_id parameter to delete a specific email message. For example:

EXEC msdb.dbo.sp_delete_dbmail @message_id = 12345

This will also delete the email message with the message ID 12345.

If you want to delete all email messages, you can use the sp_delete_dbmail stored procedure without specifying a message ID. For example:

EXEC sp_delete_dbmail

This will delete all email messages in the Database Mail queue.

Remember to replace <message_id> with the actual message ID of the email message you want to delete.