방법: 데이터베이스 메일을 통해 보낸 전자 메일 메시지의 상태 확인(Transact-SQL)

데이터베이스 메일은 보내는 전자 메일 메시지의 복사본을 유지하고 msdb 데이터베이스의 sysmail_allitems, sysmail_sentitems, sysmail_unsentitems, sysmail_faileditems 뷰에 표시합니다. 데이터베이스 메일 외부 프로그램은 작업을 기록하고 Windows 응용 프로그램 이벤트 로그와 msdb 데이터베이스의 sysmail_event_log 뷰를 통해 로그를 표시합니다. 전자 메일 메시지의 상태를 확인하려면 이 뷰에 대한 쿼리를 실행하십시오. 전자 메일 메시지에는 sent, unsent, retryingfailed의 4가지 가능한 상태가 있습니다.

전자 메일 메시지의 상태를 확인하려면

  1. sysmail_allitems 테이블에서 mailitem_id 또는 sent_status로 메시지를 선택합니다.

  2. 전자 메일 메시지에 대해 외부 프로그램에서 반환된 상태를 확인하려면 다음 섹션에 나열된 방법으로 sysmail_allitemsmailitem_id 열의 sysmail_event_log 뷰에 조인합니다.

[!참고] 기본적으로 외부 프로그램은 성공적으로 전송된 메시지에 대한 정보를 기록하지 않습니다. 모든 메시지를 기록하려면 데이터베이스 메일 구성 마법사시스템 매개 변수 구성 페이지를 사용하여 로깅 수준을 자세히로 설정하십시오.

다음 예에서는 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
  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

참고 항목

개념

데이터베이스 메일 로깅 및 감사

관련 자료

데이터베이스 메일 뷰(Transact-SQL)

도움말 및 정보

SQL Server 2005 지원 받기