December 28, 2015 at 3:52 pm
Can someone please pass me a short segment of code to send email from T-SQL.
(:-P I will run it and findout whether our server is configured correctly to send email)
Thanks in advance!
December 28, 2015 at 4:25 pm
Exercise your Googlefu, young Jedi!
December 28, 2015 at 4:56 pm
mw112009 (12/28/2015)
(:-P I will run it and findout whether our server is configured correctly to send email)
If it turns out to not be setup and no one wants to set it up, you don't actually need to set it up to send email from T-SQL. There's a trick to it. Lemme know if you need that trick.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2015 at 9:36 pm
You can see the current database mail configuration by using the following system functions
EXEC msdb.dbo.sysmail_help_configure_sp;
EXEC msdb.dbo.sysmail_help_account_sp;
EXEC msdb.dbo.sysmail_help_profile_sp;
EXEC msdb.dbo.sysmail_help_profileaccount_sp;
EXEC msdb.dbo.sysmail_help_principalprofile_sp;
December 29, 2015 at 5:23 am
Yes I need the trick
December 29, 2015 at 5:28 am
I believe this must be a permissions issue right ?
Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1
The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
December 29, 2015 at 5:31 am
Also on another server/database I get this .....
Msg 14636, Level 16, State 1, Procedure sp_send_dbmail, Line 112
No global profile is configured. Specify a profile name in the @profile_name parameter.
I beleive mail is not set up here .. right ?
December 29, 2015 at 5:37 am
1. you need to give permissions to the user that is attempting to send the mail. This is in the MSDB database, role "DatabaseMailUserRole"
EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole' ,@membername = '<user or role name>';
2. You need to configure Database Mail, or you don't have the name of the profile correct. SQL can now send mails under several profiles.
In SSMS go to:
Management, Database Mail. Right mouse click and "Configure Database Mail". from here you can also see configured profiles (if you have any on that server)
December 29, 2015 at 5:41 am
Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1
The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
check that you didn't check db_denydatareader DB role
December 29, 2015 at 5:44 am
John: Where exactly do you want me to check for that "..deny'''
December 29, 2015 at 5:46 am
Msg 14636, Level 16, State 1, Procedure sp_send_dbmail, Line 112
No global profile is configured. Specify a profile name in the @profile_name parameter.
This error occurred because none of the database mail profiles you created were set to be the "Global Profile"
December 29, 2015 at 6:00 am
mw112009 (12/29/2015)
John: Where exactly do you want me to check for that "..deny'''
In SSMS - under Databases >>mydatabase >>Security >>Users >>myusername, right click the username, select properties under database role membership “db_denydatareader”
December 29, 2015 at 6:03 am
Jeff Moden (12/28/2015)
mw112009 (12/28/2015)
(:-P I will run it and findout whether our server is configured correctly to send email)If it turns out to not be setup and no one wants to set it up, you don't actually need to set it up to send email from T-SQL. There's a trick to it. Lemme know if you need that trick.
Wait...this looks like one of those "this Simple Trick Network Admins don't want you to know" clickbaits! where's the meat and potatoes here?
Lowell
December 29, 2015 at 6:56 am
db_denydatareader is a database role, you will find it in <dbname>, Security, Users, <username>, Membership.
you can actually get to it a number of ways. I think what John is suggesting is that you don't have permissions to the data - but this is not the error message you got so I think this is a red herring
December 29, 2015 at 6:57 am
1. you need to give permissions to the user that is attempting to send the mail. This is in the MSDB database, role "DatabaseMailUserRole"
EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole' ,@membername = '<user or role name>';
2. You need to configure Database Mail, or you don't have the name of the profile correct. SQL can now send mails under several profiles.
In SSMS go to:
Management, Database Mail. Right mouse click and "Configure Database Mail". from here you can also see configured profiles (if you have any on that server)
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply