Solved

permissions to user to send email

Posted on 2011-09-16
10
900 Views
Last Modified: 2012-05-12
I have a stored procedure that sends email successfully when I'm logged in as sa.

But from one of my apps--with different credentials--I get an error about:

System.Data.SqlClient.SqlException: The EXECUTE permission was denied on the object 'sp_OACreate', database 'mssqlsystemresource', schema 'sys'.The EXECUTE permission was denied on the object 'sp_OASetProperty', database 'mssqlsystemresource', schema 'sys'.The EXECUTE permission was denied on the object 'sp_OASetProperty', database...

Fine.

So I try to start doing what every link on the web--which you're about to post in as your answer--says to do.  Like this:

grant exec on sp_OACreate to [rsuser1];
GO

But that yields:

"Cannot find the user 'rsuser1', because it does not exist or you do not have permission."

The user does exist.  It's a SQL account, not a domain account, but it does exist in SQL.

What do I need to do?  I really need some specifics.

Thanks.
0
Comment
Question by:bamapie
10 Comments
 
LVL 10

Expert Comment

by:gaurav05
ID: 36548095
Hi,

A user who already has sysadmin privileges must execute that script.
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 36548117
You say that the user rsuser1 exist, in which schema dbo or sys ?
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 36549116
Please give execute permission to that user.
0
 
LVL 3

Expert Comment

by:hspoulsen
ID: 36549176
it looks as if you are not using Database mail.
If you are on SQL Server 2005 or above, you should try that instead. Dbmail is a stable solution, whereas DCOM may cause problems from time to time.

We use database mail, and it works fine. The worst part in setting it up, is that you need access to a SMTP server. I had to have our SQL Server added to the exchange servers list of valid addresses.

Best regards,
Henrik Staun Poulsen
Stovi Software
 
0
 

Author Comment

by:bamapie
ID: 36550050
gaurav05:  I executed that script as sa.

samo4fun:  This is one of the server's logins.  Not sure what you mean.

Patel:  In my original question, I include an error message that I received after attempting to assign EXECUTE permissions to my user.

hspoulsen:  I am using SMTP.  My entire procedure looks like what you see below:

 
ALTER PROCEDURE [dbo].[spSendSMTPMail]
	@FromEmailAddress VARCHAR(32),
	@ToEmailAddress VARCHAR(128),
	@Subject VARCHAR(256),
	@Body VARCHAR(8000)
AS	

DECLARE @Message INT; 
DECLARE @HR INT; 
DECLARE @SRC VARCHAR(255);
DECLARE @DESC varchar(255);

EXEC @HR = sp_OACreate 'CDO.Message', @Message OUT;

EXEC @HR = sp_OASetProperty @Message, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value', '2'
EXEC @HR = sp_OASetProperty @Message, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'smtp2.flatsville.com'
EXEC @HR = sp_OASetProperty @Message, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value', '25'
EXEC @HR = sp_OASetProperty @Message, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value', '1'

EXEC @HR = sp_OAMethod @Message, 'Configuration.Fields.Update', NULL;

EXEC @HR = sp_OASetProperty @Message, 'To', @ToEmailAddress;
EXEC @HR = sp_OASetProperty @Message, 'From', @FromEmailAddress;
EXEC @HR = sp_OASetProperty @Message, 'Subject', @Subject;
EXEC @HR = sp_OASetProperty @Message, 'TextBody', @Body;

EXEC sp_OAMethod @Message, 'Send', NULL;

EXEC @HR = sp_OADestroy @Message;

-- Errorhandler
IF (@HR <> 0)
	BEGIN
		EXEC sp_OAGetErrorInfo @Message, @SRC OUT, @DESC OUT
		SELECT HR = CONVERT(varbinary(4),@HR), Source=@SRC, Description=@DESC;
	END

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:bamapie
ID: 36905242
No idea on this one?  I'd love to figure this out.  It's still an issue.
0
 
LVL 3

Expert Comment

by:hspoulsen
ID: 36908370
I send mails this way:
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'DatabaseMail',
@recipients = 'hsp@stovi.com', 
@body = 'lots of text', @subject = 'title/subject of mail'

Open in new window


The worst problem was to get the database server recognised as a valid email sender with our exchange server team.

Another problem that I've had has been described here: http://www.sqlservercentral.com/Forums/Topic253575-149-1.aspx

Our SQL Server send mails every day.
0
 

Author Comment

by:bamapie
ID: 36989295
Okay, I fixed this by going somewhere and adding the "send Database Mail" permission to my user accounts in question.

Problem is, I was going to post that here, but now I can't figure out where I did that.  

It was a GUI that looked like the "securables" screen.  There it was, plain as day, a permission that I turned on for my user, and bam, it started working and continues to work.

Do you know what I'm talking about?  I cannot find it for the life of me now.

0
 
LVL 3

Accepted Solution

by:
hspoulsen earned 500 total points
ID: 36991717
was it on the SQL Server Agent -> properties -> Alert System  (check the checkbox) ?
0
 

Author Closing Comment

by:bamapie
ID: 37410884
I honestly don't remember now, but...cheers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now