다음을 통해 공유


Linux에서 SQL Server 에이전트 데이터베이스 메일 및 전자 메일 경고

적용 대상: SQL Server - Linux

이 문서에서는 데이터베이스 메일을 설정하고 Linux에서 SQL Server 에이전트(mssql-server-agent)와 함께 사용하는 방법을 보여 줍니다.

1. 데이터베이스 메일을 활성화합니다

USE master;
GO

sp_configure 'show advanced options', 1;
GO

RECONFIGURE WITH OVERRIDE
GO

sp_configure 'Database Mail XPs', 1;
GO

RECONFIGURE;
GO

2. 새 계정을 만듭니다

EXECUTE msdb.dbo.sysmail_add_account_sp @account_name = 'SQLAlerts',
    @description = 'Account for Automated DBA Notifications',
    @email_address = 'sqlagenttest@example.com',
    @replyto_address = 'sqlagenttest@example.com',
    @display_name = 'SQL Agent',
    @mailserver_name = 'smtp.example.com',
    @port = 587,
    @enable_ssl = 1,
    @username = 'sqlagenttest@example.com',
    @password = '<password>';
GO

3. 기본 프로필 생성

EXECUTE msdb.dbo.sysmail_add_profile_sp
    @profile_name = 'default',
    @description = 'Profile for sending Automated DBA Notifications';
GO

4. 데이터베이스 메일 프로필에 데이터베이스 메일 계정 추가

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'default',
    @principal_name = 'public',
    @is_default = 1;
GO

5. 프로필에 계정 추가

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'default',
    @account_name = 'SQLAlerts',
    @sequence_number = 1;
GO

6. 테스트 이메일 보내기

전자 메일 클라이언트로 이동하여 보안이 낮은 클라이언트가 메일을 보낼 수 있도록 허용해야 할 수 있습니다. 모든 클라이언트가 데이터베이스 메일 전자 메일 디먼으로 인식하는 것은 아닙니다.

EXECUTE msdb.dbo.sp_send_dbmail
    @profile_name = 'default',
    @recipients = 'recipient-email@example.com',
    @subject = 'Testing DBMail',
    @body = 'This message is a test for DBMail'
GO

7. mssql-conf 또는 환경 변수를 사용하여 데이터베이스 메일 프로필 설정

mssql-conf 유틸리티 또는 환경 변수를 사용하여 데이터터베이스 메일 프로필을 등록할 수 있습니다. 이 경우 프로필을 default호출해 보겠습니다.

  • mssql-conf를 통해 설정.

    sudo /opt/mssql/bin/mssql-conf set sqlagent.databasemailprofile default
    
  • 환경 변수를 통해 설정.

    MSSQL_AGENT_EMAIL_PROFILE=default
    

8. SQL Server 에이전트 작업 알림에 대한 운영자 설정

EXEC msdb.dbo.sp_add_operator
    @name = N'JobAdmins',
    @enabled = 1,
    @email_address = N'recipient-email@example.com',
    @category_name = N'[Uncategorized]';
GO

9. '에이전트 테스트 작업'이 성공하면 전자 메일 보내기

EXEC msdb.dbo.sp_update_job
    @job_name = 'Agent Test Job',
    @notify_level_email = 1,
    @notify_email_operator_name = N'JobAdmins'
GO