SQL 2005 邮件发送问题 本帖最后由 tcshen0 于 2013-09-22 16:58:18 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --1. 启用 SQL Server 2005 邮件功能。 use mastergoexec sp_configure 'show advanced options',1goreconfiguregoexec sp_configure 'Database mail XPs',1goreconfigurego-- 2. 在 SQL Server 2005 中添加邮件帐户(account) exec msdb..sysmail_add_account_sp @account_name = 'jgj' -- 邮件帐户名称(SQL Server 使用) ,@email_address = '[email protected]' -- 发件人邮件地址 ,@display_name = null -- 发件人姓名 ,@replyto_address = null ,@description = null ,@mailserver_name = 'smtp.126.com' -- 邮件服务器地址 ,@mailserver_type = 'SMTP' -- 邮件协议(SQL 2005 只支持 SMTP) ,@port = 25 -- 邮件服务器端口 ,@username = '[email protected]' -- 用户名 ,@password = '***' -- 密码 ,@use_default_credentials = 0 ,@enable_ssl = 0 ,@account_id = null--3. 在 SQL Server 2005 中添加 profile exec msdb..sysmail_add_profile_sp @profile_name = 'dba_profile' -- profile 名称 ,@description = 'dba mail profile' -- profile 描述 ,@profile_id = null-- 在 SQL Server 2005 中映射 account 和 profile exec msdb..sysmail_add_profileaccount_sp @profile_name = 'dba_profile' -- profile 名称 ,@account_name = 'jgj' -- account 名称 ,@sequence_number = 1 -- account 在 profile 中顺序 --5. 利用 SQL Server 2005 Database Mail 功能发送邮件。 exec msdb..sp_send_dbmail @profile_name = 'dba_profile' -- profile 名称 ,@recipients = 'jimmy.qu@landcn' -- 收件人邮箱 ,@subject = 'SQL Server 2005 Mail 测试' -- 邮件标题 ,@body = 'Hello Mail!测试' -- 邮件内容 ,@body_format = 'TEXT' -- 邮件格式 --6. 查看邮件发送情况: use msdbgoselect * from sysmail_allitemsselect * from sysmail_mailitemsselect * from sysmail_event_log---------------------------------------------------------------------------------------这个里面你只需要改的地方:发件人邮件地址邮件服务器地址用户名密码这样就完全可以了 sp_send_dbmail中用到@recipients参数,表示要向其发送邮件的电子邮件地址列表,以分号分隔。此参数的类型为 varchar(max),但不确信你的邮件服务器是否支持这么长的字符串或者是否允许20个收件人。<br />真有这么多人要收信,你还是在邮件服务器那边创建一个邮件组吧。 如何在存储过程中调用函数,谢谢 错误求助:将数据类型 varchar 转换为 float 时出错。 求各位前辈一个问题,关于汇总的问题 求最简单实现 两表 拷贝数据的方法 sql server 2005 数据导出中奇怪的问题 如何精确统计某个脚本运行的时间,最后能显示出来 VFP的视图设计器 定时数据从表复制到另一表的问题,500分 这样的存储过程如何返回数据集-很简单哟 c++连接sql OTL 连接SQL ServerR2 报错 IM002 未找到源名称并且未指定默认驱动程序 这个Group怎么写呀
use master
go
exec sp_configure 'show advanced options',1
go
reconfigure
go
exec sp_configure 'Database mail XPs',1
go
reconfigure
go
-- 2. 在 SQL Server 2005 中添加邮件帐户(account)
exec msdb..sysmail_add_account_sp
@account_name = 'jgj' -- 邮件帐户名称(SQL Server 使用)
,@email_address = '[email protected]' -- 发件人邮件地址
,@display_name = null -- 发件人姓名
,@replyto_address = null
,@description = null
,@mailserver_name = 'smtp.126.com' -- 邮件服务器地址
,@mailserver_type = 'SMTP' -- 邮件协议(SQL 2005 只支持 SMTP)
,@port = 25 -- 邮件服务器端口
,@username = '[email protected]' -- 用户名
,@password = '***' -- 密码
,@use_default_credentials = 0
,@enable_ssl = 0
,@account_id = null
--3. 在 SQL Server 2005 中添加 profile
exec msdb..sysmail_add_profile_sp @profile_name = 'dba_profile' -- profile 名称
,@description = 'dba mail profile' -- profile 描述
,@profile_id = null
-- 在 SQL Server 2005 中映射 account 和 profile
exec msdb..sysmail_add_profileaccount_sp @profile_name = 'dba_profile' -- profile 名称
,@account_name = 'jgj' -- account 名称
,@sequence_number = 1 -- account 在 profile 中顺序
--5. 利用 SQL Server 2005 Database Mail 功能发送邮件。
exec msdb..sp_send_dbmail @profile_name = 'dba_profile' -- profile 名称
,@recipients = 'jimmy.qu@landcn' -- 收件人邮箱
,@subject = 'SQL Server 2005 Mail 测试' -- 邮件标题
,@body = 'Hello Mail!测试' -- 邮件内容
,@body_format = 'TEXT' -- 邮件格式
--6. 查看邮件发送情况:
use msdb
go
select * from sysmail_allitems
select * from sysmail_mailitems
select * from sysmail_event_log
---------------------------------------------------------------------------------------
这个里面你只需要改的地方:
发件人邮件地址
邮件服务器地址
用户名
密码
这样就完全可以了