22,207
社区成员
发帖
与我相关
我的任务
分享
SELECT l.mailitem_id , m.mailitem_id , send_request_date , m.sent_status , r.send_attempts
FROM dbo.sysmail_log l
LEFT JOIN dbo.sysmail_mailitems m ON m.mailitem_id = l.mailitem_id
LEFT JOIN dbo.sysmail_send_retries r ON l.mailitem_id = r.mailitem_id
WHERE l.event_type = 3
SET QUOTED_IDENTIFIER OFF
SET ANSI_NULLS ON
GO
CREATE VIEW sysmail_event_log
AS
SELECT log_id,
CASE event_type
WHEN 0 THEN 'success'
WHEN 1 THEN 'information'
WHEN 2 THEN 'warning'
ELSE 'error'
END as event_type,
log_date,
description,
process_id,
sl.mailitem_id,
account_id,
sl.last_mod_date,
sl.last_mod_user
FROM [dbo].[sysmail_log] sl
WHERE (ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0) = 1) OR
(EXISTS ( SELECT mailitem_id FROM [dbo].[sysmail_allitems] ai WHERE sl.mailitem_id = ai.mailitem_id ))
GO
SET QUOTED_IDENTIFIER OFF
SET ANSI_NULLS ON
GO
CREATE VIEW sysmail_allitems
AS
SELECT mailitem_id,
profile_id,
recipients,
copy_recipients,
blind_copy_recipients,
subject,
body,
body_format,
importance,
sensitivity,
file_attachments,
attachment_encoding,
query,
execute_query_database,
attach_query_result_as_file,
query_result_header,
query_result_width,
query_result_separator,
exclude_query_output,
append_query_error,
send_request_date,
send_request_user,
sent_account_id,
CASE sent_status
WHEN 0 THEN 'unsent'
WHEN 1 THEN 'sent'
WHEN 3 THEN 'retrying'
ELSE 'failed'
END as sent_status,
sent_date,
last_mod_date,
last_mod_user
FROM msdb.dbo.sysmail_mailitems
WHERE (send_request_user = SUSER_SNAME()) OR (ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0) = 1)
GO