SQL Server Standard 2008 R2
Kind of a weird issue. I have a couple of database procedures which call sp_send_dbmail. It worked last week. It doesn't work today. I did restart my computer between last week and today, and manually restarted the SQL Server (currently running: the DB Engine, Analysis Services, SQL Server Browser, Integration Services, and SQL Server Agent).
The login, "ProcessServeAllPermissions" is set up as a user in both this database and in the msdb database, and the user has been added to the role, "DatabaseMailUserRole".
Here's an example procedure:
I've also tried changing the EXECUTE AS statement to, "WITH EXECUTE AS OWNER", and setting up certificates by adapting the code found here:
...with no luck. No matter what, I'm always getting this error message today:
The 'User Notification Emails' profile is still set up in Database Mail, and when I right-click Database Mail (in SSMS) and send a test email, it works.
Help, please!
Katie
Kind of a weird issue. I have a couple of database procedures which call sp_send_dbmail. It worked last week. It doesn't work today. I did restart my computer between last week and today, and manually restarted the SQL Server (currently running: the DB Engine, Analysis Services, SQL Server Browser, Integration Services, and SQL Server Agent).
The login, "ProcessServeAllPermissions" is set up as a user in both this database and in the msdb database, and the user has been added to the role, "DatabaseMailUserRole".
Here's an example procedure:
Code:
CREATE PROCEDURE [dbo].[udp_SendWelcomeEmail]
-- Add the parameters for the stored procedure here
@NewUserID int
WITH EXECUTE AS 'ProcessServeAllPermissions'
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @SubjectLine varchar(1000), @BodyContent varchar(max)
DECLARE @UserPrimaryEmail varchar(200)
DECLARE @MyName varchar(200), @MyEmail varchar(200)
-- Insert statements for procedure here
-- Snipping all of the lines for setting the subject line, body content, primary email, and my email variables.
-- I've confirmed that the variables do end up getting set correctly. That's not the issue.
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'User Notification Emails',
@recipients = @UserPrimaryEmail,
@reply_to = @MyEmail,
@subject = @SubjectLine,
@body = @BodyContent
END
END
GO
I've also tried changing the EXECUTE AS statement to, "WITH EXECUTE AS OWNER", and setting up certificates by adapting the code found here:
...with no luck. No matter what, I'm always getting this error message today:
Code:
Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1
The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
The 'User Notification Emails' profile is still set up in Database Mail, and when I right-click Database Mail (in SSMS) and send a test email, it works.
Help, please!
Katie