sp_send_dbmail

  • I  have a trigger on a table that belongs to a non-dbo schema. The trigger is an after insert trigger and calls the sp_send_dbmail (I want to know if someone inserts a record in that table).

    Currently, other than users belonging to sysadmin role, only one user (user: testuser) can insert record into that table. But the user gets the error message

    EXECUTE permission denied on object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
    I know this is happening because the trigger runs unders the context of the user that causes the trigger to execute. And testuser has no permission to execute sp_send_dbmail
    The only workaround I know of is to add testuser to msdb, and add the user to the DatabaseMailUserRole role.
    I've tried a few methods, such as wrapping the sp_send_dbmail into a stored procedure belonging to the dbo schema (ie dbo.myprocedure_send_mail) and have the trigger execute dbo.myprocedure_send_mail, didn't work.
    Also tried to create the stored procedure with EXECUTE AS OWNER option, didn't work either.
    Has anyone else come across this problem? 
  • This was removed by the editor as SPAM

  • I am having this exactly problem. I'll post as soon as I figure out my fix for it. I'm going to try to assign the 'datawrite' role as an executer of this since all my users that hit the table are part of 'datawrite'

    Near Kindest Regards, Gator

  • ALTER DATABASE [database name] SET TRUSTWORTHY ON

  • Why don't you store the results that you want to mail out in a table and set up a job to run sp_send_dbmail against this table - Presumably a couple of minutes on the email wouldn't make any difference ?

  • This is what I meant with the mail_queue table and an agent that sends periodically

  • I had a similer issue , I was using Service Broker and was trying to send email after the Job of the Queue was complete. Iwas getting the error "The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'."

    I alter the database

    ALTER DATABASE [xyz] SET TRUSTWORTHY ON and my problem was resolved.

    Raj Gujar

  • Thanks to gs-627439 and Raj Gujar ... After following all the MS supplied instructions the one that was missing was the ALTER DATABASE one. Makes sense I guess given where MS is taking SQL Azure.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply