48

I have a windows account with users group and trying to exec sp_send_dbmail but getting an error:

profile name is not valid.

However, when I logged in as administrator and execute the sp_send_dbmail, it managed to send the email so obviously the profile name does exist on the server.

6 Answers 6

52

You need to grant the user or group rights to use the profile. They need to be added to the msdb database and then you will see them available in the mail wizard when you are maintaining security for mail.

Read up the security here: http://msdn.microsoft.com/en-us/library/ms175887.aspx

See a listing of mail procedures here: http://msdn.microsoft.com/en-us/library/ms177580.aspx

Example script for 'TestUser' to use the profile named 'General Admin Mail'.


USE [msdb]
GO
CREATE USER [TestUser] FOR LOGIN [testuser]
GO
USE [msdb]
GO
EXEC sp_addrolemember N'DatabaseMailUserRole', N'TestUser'
GO

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'General Admin Mail',
    @principal_name = 'TestUser',
    @is_default = 1 ;
4
  • 7
    This error can also happen if you've specified the WRONG profile name via some types of code... i.e., sp_send_dbmail @profile_name = N'Some Profile That does Not Exist', etc... will throw this error as well. Dec 29, 2014 at 21:36
  • 2
    As a heads-up, this same error can ALSO be caused if/when you've simply forgotten to let the SQL Server Agent have access to the SQL Server's Database Mail interfaces - as per this link: sqlmag.com/blog/avoiding-failed-notify-operator-email-errors Nov 11, 2015 at 23:44
  • Shout out to @MichaelK.Campbell who's comment above helped me fix this!
    – sam.tldr
    Apr 6, 2021 at 0:42
  • 2
    Looks like a dead link :( Jun 16, 2022 at 4:08
27

I got the same problem also. Here's what I did:

If you're already done granting the user/group the rights to use the profile name.

  1. Go to the configuration Wizard of Database Mail
  2. Tick Manage profile security
  3. On public profiles tab, check your profile name
  4. On private profiles tab, select NT AUTHORITY\NETWORK SERVICE for user name and check your profile name
  5. Do #4 this time for NT AUTHORITY\SYSTEM user name
  6. Click Next until Finish.
2
  • 2
    What if you don't have "NT AUTHORITY\NETWORK SERVICE" as a user in your particular instance of SQL? i resolved it another way. See my answer above.
    – Fandango68
    Nov 14, 2017 at 1:42
  • 2
    Note: for me I just needed to check my profile name as a public profile. Worked for what I needed in my dev environment. Did not need NT AUTHORITY\NETWORK SERVICE step. Feb 28, 2020 at 22:47
7

Did you enable the profile for SQL Server Agent? This a common step that is missed when creating Email profiles in DatabaseMail.

Steps:

  • Right-click on SQL Server Agent in Object Explorer (SSMS)
  • Click on Properties
  • Click on the Alert System tab in the left-hand navigation
  • Enable the mail profile
  • Set Mail System and Mail Profile
  • Click OK
  • Restart SQL Server Agent
3

profile name is not valid [SQLSTATE 42000] (Error 14607)

This happened to me after I copied job script from old SQL server to new SQL server. In SSMS, under Management, the Database Mail profile name was different in the new SQL Server. All I had to do was update the name in job script.

1

In my case, I was moving a SProc between servers and the profile name in my TSQL code did not match the profile name on the new server.

Updating TSQL profile name == New server profile name fixed the error for me.

0

In case you are using SQL Managed Instance (SQL MI) as I was, the answer is that you need to create a Database Mail Profile called "AzureManagedInstance_dbmail_profile" which is automatically used by its SQL Server Agent. This works for sending job completion notifications.

Not the answer you're looking for? Browse other questions tagged or ask your own question.