【问题标题】:Sending SMTP mail in SQL Server 2008 R2 Express在 SQL Server 2008 R2 Express 中发送 SMTP 邮件
【发布时间】:2010-07-27 14:45:59
【问题描述】:

我尝试使用:sp_send_dbmail

但我收到以下错误:

消息 15281,级别 16,状态 1, 过程 sp_send_dbmail,第 0 行
SQL Server 阻止了对过程的访问 组件的“dbo.sp_send_dbmail” '数据库邮件 XPs' 因为这个 组件被关闭作为的一部分 为此的安全配置 服务器。
系统管理员可以 启用“数据库邮件 XP”的使用 通过使用 sp_configure。更多 有关启用“数据库”的信息 Mail XPs',见“表面区域 SQL Server 书籍中的“配置” 在线。

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

但我收到以下错误:

消息 15281,级别 16,状态 1, 过程 sp_OACreate,第 1 行
SQL Server 阻止了对过程的访问 组件“Ole”的“sys.sp_OACreate” 自动化程序,因为这 组件被关闭作为的一部分 为此的安全配置 服务器。系统管理员可以 启用“Ole 自动化” 使用 sp_configure 的程序。为了 有关启用“Ole”的更多信息 自动化程序',参见“表面 SQL Server 中的区域配置” 在线图书。

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

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

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    第 1 阶段:在 ssms 中右键单击 sql server 2008r2 express/选择 facets/选择 Surface Area Configuration/set DatabaseMailEnabled ->true/单击确定。重新启动服务器

    第二阶段: 您只需要在msdb中配置一些表即可。以下是需要配置的表:

    1. sysmail_account -> 创建默认邮件帐户
    2. sysmail_profile -> 创建一个默认配置文件(sp_send_dbmail 需要这个)
    3. sysmail_profileaccount -> 根据 2 个配置文件 ID 添加相关数据
    4. sysmail_server -> 从您将用于发送电子邮件的电子邮件帐户创建一个邮件服务器。如果您不知道服务器类型,请查看 sysmail_servertype。

    更新这些表后刷新 msdb 并尝试使用 sp_send_dbmail 发送电子邮件 如果您遵循所有这些步骤,您将能够使用 sp_send_dbmail 在 sql 2008 r2 express 中发送电子邮件。 我做了 5 次测试,一切都很顺利。

    塔利欧鲁 罗利 talleyouro@hotmail.com

    【讨论】:

    • 辛苦了。不错!
    • 设置DataBaseMailEnabled = true后不需要重启
    • 使用 SQL Express Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) 为我工作
    【解决方案2】:

    原来SQL Server 2008 R2 EXPRESS版不支持邮件功能。

    【讨论】:

      【解决方案3】:

      感谢来自this site 的 Tanmaya Thopate,以下是在 Windows Server 2008 上的 SQL Express 中工作的内容:

      EXECUTE msdb.dbo.sysmail_add_account_sp
      @account_name = 'MyMail',
      @description = 'Mail account for Database Mail',
      @email_address = 'sender@domain.com',
      @display_name = 'Me',
      @username='myaccount@gmail.com',
      @password='Password',
      @mailserver_name = 'smtp.gmail.com'
      

      邮件将通过 gmail 发送到您的帐户 myaccount@gmail.com

      现在创建个人资料:

      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 :'+@@servername+ ' Test DB Email SSL '
      EXEC msdb.dbo.sp_send_dbmail @recipients='me@mywork.co.za',
      @subject = 'Test',
      @body = @body1,
      @body_format = 'HTML' ;
      

      您可以从以下位置查看日志:

      SELECT * FROM msdb.dbo.sysmail_event_log order by log_date
      

      【讨论】:

        【解决方案4】:

        我知道这个问题是针对 express 的,但是为了记录,这里是为正确的 sql server (SQL Server 2008 R2) 做些什么:

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

        • 连接到管理工作室中的服务器
        • 右键单击服务器
        • 点击“构面
        • 在 Facet 下拉菜单中,选择“Surface Area Configuration
        • 双击“DatabaseMailEnabled”行将其设置为“True”。

        【讨论】:

          【解决方案5】:

          请执行以下脚本:

          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;
          

          【讨论】:

          • 答案应该包含更多关于实际正在做什么、问题是什么的信息,而不仅仅是“执行这个”解决方案。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-01-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-14
          相关资源
          最近更新 更多