728x90

MSSQL 2005에서 지원되는 dbmail을 사용하기 위한 방법 을 그냥 나열

일단 준비단계
------------------------------------------------------
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = '계정이름 - hugyou',
    @description = '계정설명 - 전지전능하지 못한 hugyou',
    @email_address = '메일주소 - xxx@xxx.net',
    @display_name = '보여질 이름 - 메일 받을때 발신인에 찍힐 이름',
    @username='메일주소 - xxx@xxx.net or other',
    @password='비밀번호 - 비번',
    @mailserver_name = 'SMTP 서버 주소 - smtp.smtp.com'
go

EXECUTE msdb.dbo.sysmail_add_profile_sp
       @profile_name = '계정이름',
       @description = 'Profile used for 계정이름'
go

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = '계정이름',
    @account_name = '계정이름',
    @sequence_number = 1
go

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = '계정이름',
    @principal_name = 'public',
    @is_default = 1 ;
go

------------------------------------------------------



이제 보내봅시다
------------------------------------------------------
declare @body1 varchar(100)
set @body1 = '서버 :'+@@servername+ ' 첫 메일!'
EXEC msdb.dbo.sp_send_dbmail @recipients='보낼메일 주소 to@to.com 등등..',
    @profile_name = '계정이름',
    @subject = '메일 테스트',
    @body = @body1,
    @body_format = 'HTML' ;
------------------------------------------------------


다른 옵션은 books online의 sp_send_dbmail 을 찾아보시면 쿼리 결과를 그대로 보내는 법 등이 나와있음 입니다 :)

+ Recent posts