DB mail真的很方便,只是感觉比SQL mail发邮件稍慢一些!--enable DB mail XPs use master go sp_configure 'show advanced options',1 go reconfigure with override go sp_configure 'Database Mail XPs',1 --go --sp_configure 'SQL Mail XPs',0 go reconfigure go--create DB mail account and DB mail profile EXECUTE msdb.dbo.sysmail_add_account_sp @account_name = account_name, @description = '', @email_address =email_address , @replyto_address=replyto_address, @display_name =display_name , @username=username, @password=password, @mailserver_name =mailserver_name/IP exec msdb.dbo.sysmail_add_profile_sp @profile_name='ProfileTest', @description='';exec msdb.dbo.sysmail_add_profileaccount_sp @profile_name='ProfileTest', @account_name=account_name, @sequence_number=1;exec msdb.dbo.sysmail_add_principalprofile_sp @principal_name='public', @profile_name='ProfileTest', @is_default=1; --test to send DB mail exec msdb.dbo.sp_send_dbmail @profile_name ='ProfileTest', @[email protected]', @copy_recipients='', @blind_copy_recipients='', @subject=' Mail subject', @body='MAIL body', @body_format='HTML', --TEXT ;HTML
1 Windows 2000 Server
2 SQL Server 2000 SP3
3 Microsoft Outlook (Office 2000)
准备一个Internet邮件帐户:
测试电子邮件帐户:[email protected]
Smtp服务器 smtp.163.com
pop3服务器 pop.163.com
步骤一: 更改电子邮件配置
1 打开Microsoft Outlook 单击“工具”菜单中的“选项”,然后单击“邮件服务”选项卡。
2 单击“重新配置邮件支持”。
3 选择“用于企业或工作组”选项
4 重新启动Microsoft Outlook
步骤二: 添加配置文件
1 单击“工具”菜单中的“服务”,然后单击“添加”按钮。
2 选择"Internet 电子邮件",单击“确定”。
3 下面的步骤是设置电子邮件帐号,请参考Microsoft Outlook帮助文件,这里不再赘述。
4 利用配置好的电子邮件帐号收发邮件,确认配置成功。
步骤三: 配置MSSQLSERVER服务采用邮件配置文件
1 重新启动MSSQLSERVER服务(必须的,否则MSSQLSERVER服务检测不到上一步骤添加的配置文件)
2 打开企业管理器->展开服务器->支持服务->右击"邮件"->点击下拉框,你会发现
"Microsoft Outlook Internet Settings"选项,点击"测试"。如果弹出表示成功的对话框,那恭喜你,已经 大功告成了。
步骤四:享受你的劳动成果
1 打开SQL Server的查询分析器
2 输入下列SQL语句,执行
exec master..xp_sendmail [email=]'[email protected]','Hello,World!'[/email]
3 好了,去你的邮箱收邮件去吧!
注意事项:以上的配置过程要求以MSSQLSERVER服务采用的Windows帐号登录Windows 2000 Server,即你登录计算机所采用的帐号要和MSSQLSERVER服务采用的Windows帐号相同。
2,用sp_send_dbmail系统存储过程发送邮件。具体方法看帮助吧。
use master
go
sp_configure 'show advanced options',1
go
reconfigure with override
go
sp_configure 'Database Mail XPs',1
--go
--sp_configure 'SQL Mail XPs',0
go
reconfigure
go--create DB mail account and DB mail profile
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = account_name,
@description = '',
@email_address =email_address ,
@replyto_address=replyto_address,
@display_name =display_name ,
@username=username,
@password=password,
@mailserver_name =mailserver_name/IP
exec msdb.dbo.sysmail_add_profile_sp
@profile_name='ProfileTest',
@description='';exec msdb.dbo.sysmail_add_profileaccount_sp
@profile_name='ProfileTest',
@account_name=account_name,
@sequence_number=1;exec msdb.dbo.sysmail_add_principalprofile_sp
@principal_name='public',
@profile_name='ProfileTest',
@is_default=1;
--test to send DB mail
exec msdb.dbo.sp_send_dbmail
@profile_name ='ProfileTest',
@[email protected]',
@copy_recipients='',
@blind_copy_recipients='',
@subject=' Mail subject',
@body='MAIL body',
@body_format='HTML', --TEXT ;HTML