Skip to main content

Posts

Showing posts from 2020

How to grant sendmail permission to sql server user?

Create a mail profile first using 1. Management - > Database Mail object 2. Create the desired user under Security -> Logins object Run the following permission script use msdb exec sp_addrolemember 'DatabaseMailUserRole' , 'sqlUser' EXECUTE msdb . dbo . sysmail_add_principalprofile_sp @ principal_name = 'sqlUser' , @ profile_name = 'sqlMailProfileName' , @ is_default = 0

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 +