如何设置对 MSSQL 2005 数据库邮件的访问?
我刚刚在 MSSQL 2005 中设置了数据库邮件。我已经能够从服务器上的管理员帐户并通过 SQL Server 代理作业发送电子邮件。 但是,当我尝试通过只能访问我们的 Web 应用程序数据库的登录名发送电子邮件时,我无法发送电子邮件。
设置数据库邮件访问的最佳方法是什么?
我有 2 个高级用户想要发送电子邮件。
- 通过 SQL Server 代理安排作业来运行执行某些处理然后发送电子邮件的存储过程。 (这不是问题)
- 从 Web 应用程序调用一个存储过程,该应用程序调用另一个可以发送电子邮件的存储过程。 (这是我的权限问题)
可能的解决方案
我发现向登录授予权限的唯一方法是将登录映射到msdb 数据库并授予public 和DatabaseMailUserRole。 这确实让我担心,因为我认为这可以提供对 msdb 数据库的大量访问权限。
将我想要发送的电子邮件存储在一个表中,然后让 SQL Server 代理作业经常查看该表以发送任何排队的电子邮件。 这样,Web 应用程序的数据库登录就不会执行 [msdb].[dbo].[sp_send _dbmail] 调用,因此不需要 msdb 数据库的任何权限。
还有其他解决方案吗?
I've just setup Database mail within MSSQL 2005. I have been able to send email from an administrator account on the server and through a SQL Server Agent job. But, I unable to send email when I tried to send email via a login that just has access to a database for our web application.
What is the best way to set up access to Database Mail?
I have 2 senerios where I want to send email.
- Schedule a job through SQL Server Agent to run a Stored Procedure that does some process and then sends an email. (this hasn't been a problem)
- Have a stored procedure invoked from a web application that calls another stored procedure which could send an email. (this is were my permissions issue is)
Possible Solutions
The only way that I have found to grant permission to a login is to map the login to the msdb database and grant the public and DatabaseMailUserRole. This really concerns me as I would assume that this gives to much access to the msdb database.
Store the email I want to send in a table and then have a SQL Server Agent job look at that table every so often to send any queued emails. This way the database login for the web application does not execute the [msdb].[dbo].[sp_ send _dbmail] call and thus does not need any permission to the msdb database.
Are there any other solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够创建一个存储过程WITH EXECUTE AS OWNER选项,以便它在所有者而不是调用者的上下文中运行。
You should be able to create a stored procedure WITH EXECUTE AS OWNER option so it runs in the context of the owner rather than the caller.
我正在尝试做同样的事情,但执行
并不能解决这个问题。 使此过程正常工作的唯一事情是不添加
(我仅使用“WITH ENCRYPTION”创建它)并将运行此过程的用户添加到 msdb DatabaseMailUserRole 角色:
谢谢
I'm trying to do the same but executing
is not fixing this issue. Only thing which is making this procedure to work is not adding
(I'm creating it with "WITH ENCRYPTION" only) and adding user which will be running this procedure to msdb DatabaseMailUserRole role:
Thanks