2012-09-17 75 views
1

我正在尝试发送Sproc结果的电子邮件。我曾试着这样做:将Sproc结果发送到SQL Server中的电子邮件

EXEC msdb.dbo.sp_send_dbmail 
    @recipients = '[email protected]', 
    @query = 'EXEC test_email' , 
    @subject = 'Sample Data', 
    @attach_query_result_as_file = 1 ; 

它给了我下面的错误:

Msg 15281, Level 16, State 1, Procedure sp_send_dbmail, Line 0
SQL Server blocked access to procedure 'dbo.sp_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Database Mail XPs' by using sp_configure. For more information about enabling 'Database Mail XPs', see "Surface Area Configuration" in SQL Server Books Online.

是否有任何其他方式做到这一点?

+7

我觉得这里的错误信息实际上很有帮助。您是否尝试与您的DBA检查以启用所需的SQL Server组件来发送电子邮件? – dcp

回答

3

没有其他的方式使用DBMail我害怕。数据库邮件需要启用: EXEC sp_configure'数据库邮件XPs',1 但是,另外,数据库邮件需要配置一个适当的配置文件和帐户。

解决方法1:我用于策略不启用邮件的服务器是让存储过程调用运行查询并发送电子邮件的SSIS包。这完全绕过了数据库邮件,并且SSIS包与SMTP服务器建立了自己的连接。

我通常设置的方法是运行sp_startjob调用服务器代理作业,然后运行SSIS包。

希望这会有所帮助。

皮特

相关问题