Create Database Mail Private Profile In Sql Server

This T-SQ script can be used to setup Database Mail: to setup Database Mail account and to create a profile.

--STEP 1
 
USE [master]
GO
sp_configure 'show advanced options', 1 
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs', 1 
GO
RECONFIGURE 
GO
 
--STEP 2
IF NOT EXISTS ( SELECT  NULL
                FROM    msdb.dbo.sysmail_account
                WHERE   name = 'SQLMail' ) 
    EXECUTE msdb.dbo.sysmail_add_account_sp @account_name = 'SQLMail',
        @description = 'SQLMail', @email_address = 'dldba@rsc.org',
        @display_name = 'SQL Mail', @mailserver_name = 'SMTP SERVERNAME'   
GO
 
--STEP 3
IF NOT EXISTS ( SELECT  NULL
                FROM    msdb.dbo.sysmail_profile
                WHERE   name = 'SQLMail' ) 
    EXECUTE msdb.dbo.sysmail_add_profile_sp @profile_name = 'SQLMail',
        @description = 'SQLMail'
GO
 
--STEP 4
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp @profile_name = 'SQLMail',
    @account_name = 'SQLMail', @sequence_number = 1
GO
 
--STEP 5
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp @profile_name = 'SQLMail',
    @principal_name = 'public', @is_default = 1 ;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License