2010-07-27 102 views
8

我试着使用:sp_send_dbmail发送SMTP邮件在SQL Server 2008 R2快速

但我得到了以下错误:

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.

我也尝试使用此代码来发送SMTP邮件在SQL Server 2008中R2 EXPRESS: http://www.freevbcode.com/ShowCode.asp?ID=6699

但我收到以下错误:

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

我去了“Facets”检查那里的安全选项,但没有关于“Surface Area Configuration”的内容!它是否缺少,因为我正在使用Express版本的SQL Server 2008 R2?还是我走错了方向?

如果您有任何更好的代码/建议在SQL Server 2008中发送邮件,请让我知道。谢谢!

回答

5

原来,SQL Server 2008 R2 EXPRESS版本没有支持邮件功能。

2

我知道这个问题是明确的,但对于这里的战绩是什么正确的SQL服务器(SQL Server 2008 R2中)做:

http://www.mssqltips.com/tip.asp?tip=1673

  • 连接到服务器管理工​​作室
  • 右键单击该服务器
  • 点击 “刻面
  • 在小面下拉列表中,选择“ 外围应用配置
  • 双击” DatabaseMailEnabled“行设置为” ”。
16

阶段1:SQL Server上右击2008R2快递SSMS中/选择面/选择外围应用配置/设置DatabaseMailEnabled - >真/点击ok.Restart服务器

阶段2: 你只需要配置内msdb.Here一些表格是需要配置表:

  1. sysmail_account - >创建一个默认的邮件帐户
  2. sysmail_profile - >创建默认配置文件(你需要这个以sp_send_db邮件)
  3. sysmail_profileaccount - >相关数据添加到这个基于2个人资料编号
  4. sysmail_server - >创建您将使用发送emails.If你不知道服务器类型往里电子邮件帐户的邮件服务器sysmail_servertype。

更新这些表刷新MSDB后以及使用sp_send_dbmail 如果你遵循了所有这些步骤,你将能够以SQL 2008 R2 Express来使用sp_send_dbmail中发送电子邮件尝试发送电子邮件。 我做了5个测试,它进行得很顺利。

塔利欧鲁普雷 罗利 [email protected]

+2

工作一种享受。好一个! – paulH 2012-12-19 13:19:37

+0

设置DataBaseMailEnabled = true后我不需要重新启动 – sreimer 2013-07-24 15:09:44

+0

使用SQL Express为我工作Microsoft SQL Server 2008 R2(SP1) - 10.50.2500.0(X64) – 2013-09-10 15:39:35

0

请执行以下脚本:

sp_configure 'show advanced options', 1 
GO 
RECONFIGURE; 
GO 
sp_configure 'Ole Automation Procedures', 1 
GO 
RECONFIGURE; 
GO 
sp_configure 'show advanced options', 1 
GO 
RECONFIGURE; 
+0

答案应包含有关实际正在进行的操作的更多信息,是问题,而不仅仅是“执行这个”解决方案。 – lejlot 2013-12-28 09:11:21

4

this site一些信贷Tanmaya Thopate,这里的东西,在SQL Express的Windows上运行Server 2008:

EXECUTE msdb.dbo.sysmail_add_account_sp 
@account_name = 'MyMail', 
@description = 'Mail account for Database Mail', 
@email_address = '[email protected]', 
@display_name = 'Me', 
@username='[email protected]', 
@password='Password', 
@mailserver_name = 'smtp.gmail.com' 

邮件将通过Gmail与您的帐户发送我的[email protected]

现在创建一个配置文件:

EXECUTE msdb.dbo.sysmail_add_profile_sp 
@profile_name = 'MyMailProfile', 
@description = 'Profile needed for database mail' 

链接配置文件到邮件

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp 
@profile_name = 'MyMailProfile', 
@account_name = 'MyMail', 
@sequence_number = 1 


EXECUTE msdb.dbo.sysmail_add_principalprofile_sp 
@profile_name = 'MyMailProfile', 
@principal_name = 'public', 
@is_default = 1 ; 

确保SSL被启用,否则Gmail会抱怨。

use msdb 
UPDATE sysmail_server 
SET enable_ssl = 1 

和发送邮件有:

declare @body1 varchar(100) 
set @body1 = 'Server :'[email protected]@servername+ ' Test DB Email SSL ' 
EXEC msdb.dbo.sp_send_dbmail @recipients='[email protected]', 
@subject = 'Test', 
@body = @body1, 
@body_format = 'HTML' ; 

您可以从查看日志:

SELECT * FROM msdb.dbo.sysmail_event_log order by log_date