Files
DBAdmin/inbox/DataBase/SQLServer/agent/agent_mail.sql
T
2026-05-18 06:40:19 +00:00

13 lines
617 B
SQL

Use the below query to get details for all emails sent the same date:
SELECT * FROM msdb..sysmail_mailitems WHERE sent_date > DATEADD(DAY, -1,GETDATE())
And here is the complete query to get all the failed emails from the past 24 hours:
SELECT items.subject ,
items.recipients ,
items.copy_recipients ,
items.blind_copy_recipients ,
items.last_mod_date ,
l.description
FROM msdb.dbo.sysmail_faileditems AS items
LEFT OUTER JOIN msdb.dbo.sysmail_event_log AS l
ON items.mailitem_id = l.mailitem_id
WHERE items.last_mod_date > DATEADD(DAY, -1,GETDATE())