本文我们将讨论下关于如何使用Database Mail在数据库中发送邮件。在这之前可以了解下Database Mail和SQL Mail的区别。Database Mail取代SQL Mail并提供了更多功能。所以现在升级使用Database Mail ,放弃SQL Mail。

在SQL Server中发送Emai,共有3个步骤。
1.创建策略规则和账户
2.配置Email
3.发送Email

第一步:创建策略和账户

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

【翻译】SQL SERVER 2008 发送DataBase Mail

第二步:配置Email

成功创建策略和账户后, 我们需要配置Database Mail.

sp_CONFIGURE 'show advanced', 1 GO RECONFIGURE GO sp_CONFIGURE _
'Database Mail XPs', 1 GO RECONFIGURE GO

【翻译】SQL SERVER 2008 发送DataBase Mail

第三步:发送Email

在配置好后,准备发送email. 发送邮件, 我们需要执行存储过程"sp_send_dbmail”

USE msdb GO EXEC sp_send_dbmail @profile_name='PinalProfile', _
@recipients='test@Example.com', @subject='Test message', _
@body='This is the body of the test message. _
Congrats Database Mail Received By you Successfully.'

【翻译】SQL SERVER 2008 发送DataBase Mail

注释:

sysmail_mailitems :存放已发送的邮件状态

sysmail_sentitems :邮件发送成功(sent_status =1),失败(sent_status =2),未发送(sent_status =3

sysmail_log:日志

【翻译】SQL SERVER 2008 发送DataBase Mail

 

相关文章: