Nitesh Kumar
Nitesh Kumar

Reputation: 885

How to grant sendmail permission to sql server user?

I have a database user which is the owner of the database. The application requirement is to send mail using database mail of sql server .

Is there any way that I can add grant only send mail permission to that user?

I have a user named testuser having server roles public and is db_owner for 1 database. Please tell me the way that I don`t need to give sysadmin serverroles to that user.

Upvotes: 13

Views: 57333

Answers (3)

Tequila
Tequila

Reputation: 864

You need to assign the login (or a role) to the mail profile after adding it to the database mail role. For the script below, a default of one may need to be set, instead of zero.

use msdb
exec sp_addrolemember 'DatabaseMailUserRole', 'sqlUser'

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp  
@principal_name = 'sqlUser',  
@profile_name = 'sqlMailProfileName',
@is_default = 0 

Upvotes: 4

Dinesh vishe
Dinesh vishe

Reputation: 3598

enter image description here

you need add 'DatabasemailUserRole' for MSDB database to user

Upvotes: 4

shiva
shiva

Reputation: 251

Please try with the below 2 options.

USE msdb;
--add our user
CREATE USER  ClarkKent FOR LOGIN  ClarkKent; 
--give this user rights to use dbmail
exec sp_addrolemember 'DatabaseMailUserRole', 'ClarkKent'

now if we know ClarkKent is getting his authorization from a windows group, then you add that windows group as a user, and add that group to the same role;

USE msdb;
--add our user via a group we know he is in 
CREATE USER 'mydomain\BusinessGroup' FOR LOGIN   'mydomain\BusinessGroup'; 
--give this GROUP rights to use dbmail
exec sp_addrolemember 'DatabaseMailUserRole', 'mydomain\BusinessGroup'

Upvotes: 16

Related Questions