简体   繁体   English

从SQL Server 2005/2008发送电子邮件

[英]Send email from SQL Server 2005 / 2008

I have to send emails from SQL Server 2005 or 2008. I have done this in the past with additional stored procedures ( sp_send_html_mail ) and complex configuration / activations. 我必须从SQL Server 2005或2008发送电子邮件。过去,我通过其他存储过程( sp_send_html_mail )和复杂的配置/激活来做到这一点。 Is there standard build-in stored procedure which sends email via SMTP (not MAPI/CAPI/Outlook profiles)? 是否有通过SMTP(不是MAPI / CAPI / Outlook配置文件)发送电子邮件的标准内置存储过程? I found sp_send_dbmail on this topic but not sure is it the only one and what security issues are possible (except spam)? 我在此主题上找到了sp_send_dbmail ,但不确定是否是唯一一个,并且可能sp_send_dbmail哪些安全问题(垃圾邮件除外)?

Yes, sp_send_dbmail is the one to use for both SQL Sever 2005 and 2008. 是的, sp_send_dbmail是用于SQL Sever 2005和2008的一种。

You will need to make sure it has been configured on your server. 您将需要确保已在服务器上对其进行了配置。 It's been a while since I did such a config, but if memory serves me correctly, it is off by default. 自从我进行这样的配置已经有一段时间了,但是如果内存能够正确为我服务,则默认情况下它处于关闭状态。 Have a look at the MS docs for that process, Configure Database Mail . 查看该过程的MS docs 配置数据库邮件 Setting an SMTP server is doable as well. 设置SMTP服务器也是可行的。 There are lots of options in there so give it a thorough review. 那里有很多选择,因此请对其进行彻底的审查。

If you are worried about unwanted use of that sp you can use roles and/or execute permission to limit access to it. 如果您担心不必要地使用该sp,则可以使用角色和/或执行权限来限制对该sp的访问。 From the MS docs on troubleshooting dbmail: 从有关对dbmail进行故障排除的MS文档中:

To send Database mail, users must be a user in the msdb database and a member of the DatabaseMailUserRole database role in the msdb database. 若要发送数据库邮件,用户必须是msdb数据库中的用户,并且是msdb数据库中DatabaseMailUserRole数据库角色的成员。 To add msdb users or groups to this role use SQL Server Management Studio or execute the following statement for the user or role that needs to send Database Mail. 要将msdb用户或组添加到该角色,请使用SQL Server Management Studio或对需要发送数据库邮件的用户或角色执行以下语句。

EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole'
    ,@membername = '<user or role name>';
GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM