Wednesday, April 5, 2023

Profile name is not valid - SQL-Serer Database Mail

Problem

When trying to send emails from SQL Server using using the sp_send_dbmail stored procedure the following error can appear (on SQL Server 2005 or 2008):
  1. EXECUTE msdb.dbo.sp_send_dbmail
  2. @profile_name = 'PROFILE_NAME', -- Change This
  3. @recipients = 'recipient@domain.com', -- Change This
  4. @Subject = 'Test Message generated from SQL Server DatabaseMail',
  5. @Body = 'This is a test message from SQL Server DatabaseMail'

Msg 14607, Level 16, State 1, Procedure sp_send_dbmail, Line 141
profile name is not valid

The Database Mail feature is installed and configured (the Database Mail feature is enabled and the necessary account and profile is created). As sysadmin the emails are send successfully using sp_send_dbmail stored procedure.
The problem appear when trying to call the sp_send_dbmail stored procedure as a non-sysadmin login. Also the executing non-syadmin login has been added to DatabaseMailUserRole role in msdb database.


Cause
This happens because there the database mail profile is not set with public access and the login is not allowed to use the specified profile.

 
Solution:
1. Set the profile used as Public
Right click on the Database Mail in Management Studio and select the Configure Database Mail menu option.


Choose Manage profile security

Go to Public Profiles, select your profile name and then set the profile as Public.

OR
2. Go to Private Profiles and grant rights to use the specified profile to the login that executes the sp_send_dbmail stored procedure.

No comments:

Post a Comment