我尝试使用:sp_send_dbmail
但是我收到以下错误:
消息15281,级别16,状态1,过程sp_send_dbmail,行0
SQL Server阻止访问组件'Database Mail XPs'的过程'dbo.sp_send_dbmail',因为此组件作为此服务器的安全配置的一部分被关闭.
系统管理员可以使用sp_configure启用"Database Mail XPs".有关启用"数据库邮件XP"的详细信息,请参阅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 Automation Procedures"的过程"sys.sp_OACreate",因为此组件作为此服务器的安全性配置的一部分被关闭.系统管理员可以使用sp_configure启用"Ole Automation Procedures".有关启用"Ole Automation Procedures"的详细信息,请参阅SQL Server联机丛书中的"Surface Area Configuration".
我去了"Facets"来检查那里的安全选项,但没有关于"Surface Area Configuration"的内容!是否缺少因为我使用的是SQL Server 2008 R2的Express版本?还是我朝错误的方向走?
如果您有任何更好的代码/建议在SQL Server 2008中发送邮件,请告诉我.谢谢!
小智 16
第1阶段:右键单击sql server 2008r2 express在ssms/choose facets /中选择Surface Area Configuration/set DatabaseMailEnabled - > true/click ok.Restart服务器
阶段2:您只需要在msdb中配置一些表.这里是需要配置的表:
更新这些表刷新msdb并尝试使用sp_send_dbmail发送电子邮件如果您执行了所有这些步骤,您将能够使用sp_send_dbmail在sql 2008 r2 express中发送电子邮件.我做了5次测试,但进展顺利.
Talley Ouro Raleigh talleyouro@hotmail.com
有了这个网站 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'
Run Code Online (Sandbox Code Playgroud)
邮件将通过gmail与您的帐户myaccount@gmail.com一起发送
现在创建个人资料:
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'MyMailProfile',
@description = 'Profile needed for database mail'
Run Code Online (Sandbox Code Playgroud)
将个人资料链接到邮件
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 ;
Run Code Online (Sandbox Code Playgroud)
确保启用SSL,否则Gmail会抱怨.
use msdb
UPDATE sysmail_server 
SET enable_ssl = 1
Run Code Online (Sandbox Code Playgroud)
并发送邮件:
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' ;
Run Code Online (Sandbox Code Playgroud)
您可以从以下位置查看日志:
SELECT * FROM msdb.dbo.sysmail_event_log order by log_date
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           37165 次  |  
        
|   最近记录:  |