Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'profile name is not valid' error when executing the sp_send_dbmail command

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.

like image 673
user384080 Avatar asked Aug 16 '10 06:08

user384080


People also ask

What is profile name in SP send Dbmail?

[ @profile_name = ] 'profile_name' Is the name of the profile to send the message from. The profile_name is of type sysname, with a default of NULL. The profile_name must be the name of an existing Database Mail profile.

How can change SQL Server profile name?

On the Manage Profiles and Accounts page, select Create a new profile option, and click Next. On the New Profile page, specify the Profile name, Description and add accounts to be included in the profile, and click Next.

How do I find my SQL Server profile name?

When a profile name or profile id is specified, sysmail_help_profile_sp returns information about that profile. Otherwise, sysmail_help_profile_sp returns information about every profile in the SQL Server instance. The stored procedure sysmail_help_profile_sp is in the msdb database and is owned by the dbo schema.

How can I tell if Dbmail is enabled?

Is it Enabled? First to check to make sure that Database Mail is enabled. Look in 'sys. configurations' for the setting Database Mail XPs, and if it is set to 0, Database Mail is not enabled.


1 Answers

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 ; 
like image 91
Sam Avatar answered Sep 17 '22 02:09

Sam