Skip to main content

Posts

Showing posts from February, 2020

Script SQL Mail Profiles when migrating databases

The following script obtains all the mail profiles, which could be used to recreate the settings on another server or test server. . USE msdb GO Declare @TheResults varchar(max),         @vbCrLf CHAR(2) SET @vbCrLf = CHAR(13) + CHAR(10) SET @TheResults = ' use master go sp_configure ''show advanced options'',1 go reconfigure with override go sp_configure ''Database Mail XPs'',1 --go --sp_configure ''SQL Mail XPs'',0 go reconfigure go ' SELECT @TheResults = @TheResults  + ' --################################################################################################# -- BEGIN Mail Settings ' + p.name + ' --################################################################################################# IF NOT EXISTS(SELECT * FROM msdb.dbo.sysmail_profile WHERE  name = ''' + p.name + ''')   BEGIN     --CREATE Profile [' + p.name +