triggerssql-server-2012database-mail

sp_send_dbmail not sending Email when row inserted from Website


I have a table in which if row is inserted I send a notification email. It works fine if I insert a row manually using SQL Server Management Studio, but fails if I insert a row from Web Interface. Jsut can't figure out why it would fail with insert from web UI? Here's the code for sending email:

exec msdb.dbo.sp_send_dbmail 
@profile_name = 'ABC',  
@recipients = @to, 
@subject = @subject, 
@body = @body

Solution

  • I figured out the solution. The problem was with Profile settings of database mail. The profile I was using was set as Private. So the process that was adding row to the table via website did not have permission to use database mail. I couldn't figure out under which id changes were made to the database via UI. But I created a public profile and used that to send email.