적용 대상:SQL Server
Azure SQL Managed Instance
이 문서에서는 Transact-SQL을 사용하여 SQL Server의 데이터베이스 메일을 사용하여 보낸 전자 메일 메시지의 상태를 확인하는 방법을 설명합니다.
- 데이터베이스 메일은 발신 전자 메일 메시지의 복사본을 저장하고
sysmail_allitems
데이터베이스의sysmail_sentitems
,sysmail_unsentitems
,sysmail_faileditems
,msdb
보기에서 이를 표시합니다. - 데이터베이스 메일 외부 프로그램은 활동을 기록하고 Windows 애플리케이션 이벤트 로그 및
sysmail_event_log
데이터베이스의msdb
보기를 통해 로그를 표시합니다. - 전자 메일 메시지에는 전송, 보내지 않음, 재시도 및 실패의 네 가지 상태 중 하나가 있습니다.
전자 메일 메시지의 상태를 확인하려면 시스템 보기에 대해 쿼리를 msdb.dbo.sysmail_event_log
실행합니다.
Transact-SQL 사용하여 데이터베이스 메일을 사용하여 보낸 전자 메일의 상태를 확인합니다.
sysmail_allitems
테이블에서 선택하고,mailitem_id
또는sent_status
를 통해 관심 있는 메시지를 지정합니다.전자 메일 메시지에 대한 외부 프로그램에서 반환된 상태를 확인하려면
sysmail_allitems
를sysmail_event_log
과 조인하여mailitem_id
열에서 확인하십시오.기본적으로 외부 프로그램은 성공적으로 전송된 메시지에 대한 정보를 기록하지 않습니다. 모든 메시지를 기록하려면 데이터베이스 메일 구성 마법사 의 시스템 매개 변수 구성페이지를 사용하여 로깅 수준을 자세히로 설정하세요.
다음 예제에서는 외부 프로그램에서 성공적으로 보낼 수 없는 danw
로 보낸 전자 메일 메시지에 대한 정보를 나열합니다. 이 문에는 제목, 외부 프로그램이 메시지를 보내지 못한 날짜 및 시간, 데이터베이스 메일 로그의 오류 메시지가 나열됩니다.
USE msdb ;
GO
-- Show the subject, the time that the mail item row was last
-- modified, and the log information.
-- Join sysmail_faileditems to sysmail_event_log
-- on the mailitem_id column.
-- In the WHERE clause list items where danw was in the recipients,
-- copy_recipients, or blind_copy_recipients.
-- These are the items that would have been sent
-- to danw.
SELECT items.subject,
items.last_mod_date
,l.description
FROM dbo.sysmail_faileditems AS items
INNER JOIN dbo.sysmail_event_log AS l
ON items.mailitem_id = l.mailitem_id
WHERE items.recipients LIKE '%danw%'
OR items.copy_recipients LIKE '%danw%'
OR items.blind_copy_recipients LIKE '%danw%';
GO