zjcxc(邹建)的Blog - SQL Server

引用或者转载本BLOG的文章请注明原作者和出处,并保留原文章中的版权信息。谢谢!

用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
zjcxc的公告
<img src="http://album.hi.csdn.net/app_uploads/zjcxc/20081204/121324264.p.jpg" border="0" height="128"></img> <img src="http://album.hi.csdn.net/app_uploads/zjcxc/20081204/122431717.p.png" border="0" width="174"></img> <table> <tr> <td> <b>嗨,您好!欢迎到zjcxc(邹建)的Blog</b> </td > </tr> <tr> <td><font color=red><b> <p algin='right'>引用或者转载本BLOG的文章请注明原作者和出处,并保留原文章中的版权信息</p></b></font> </td> </tr> <tr> <td></td> </tr> <tr> <td valign='bottom'> 我的第二本书<strong><font color=blue> 《深入浅出——SQL Server 2005开发、管理与应用实例》</font> </strong> <p> <b> <a href='http://www.china-pub.com/38462'>中国互动出版社</a> </b> <b> <a href='http://product.dangdang.com/product.aspx?product_id=20165951'>当当网</a> </b> <b> <a href='http://blog.csdn.net/zjcxc/archive/2008/03/27/2222444.aspx'>销售商列表</a> </b> </p> </td> </tr> </table>
文章分类
我写的书
《中文版SQL Server 2000开发与管理应用实例》源代码下载
《深入浅出——SQL Server 2005开发、管理与应用实例》 - 当当网
《深入浅出——SQL Server 2005开发、管理与应用实例》- 中国互动出版社
学习资源
如果您对SQL Server有任何问题,请直接至微软中文技术论坛SQL Server 板块查看您想获得的各种资讯
教程在线
自建网站
先知电脑有限公司
存档

原创  在 SQL Server 2005/2008 中,使用 Gmail 帐号配置数据库邮件功能 收藏

下面的脚本演示,在 SQL Server 2005/2008 中,使用 Gmail 帐号配置数据库邮件功能

 

-- =================================================

-- 启用数据库邮件功能

-- =================================================

EXEC sys.sp_configure N'show advanced options', 1

RECONFIGURE;

 

EXEC sys.sp_configure 'Database Mail XPs', 1;

RECONFIGURE;

 

 

-- =================================================

-- 配置

-- =================================================

DECLARE

    @account_name sysname,

    @profile_name sysname;

SELECT

    @account_name = N'GmailTest@gmail.com',  -- 数据库邮件帐号

    @profile_name = N'gmail';                -- 数据库邮件配置文件名

 

-- 数据库邮件帐号

EXEC msdb.dbo.sysmail_add_account_sp

    @account_name = @account_name,

    @email_address = N'GmailTest@gmail.com',  -- Email 地址

    @display_name = N'gmail test',            -- 回复地址

    @mailserver_name = N'smtp.gmail.com',     -- Gmail smtp 服务器地址

    @port = 25,                               -- 端口号(对于Gmail, 如果 25 不通则改用 456)

    @username = N'GmailTest@gmail.com',       -- Gmail 邮件地址

    @password = N'abc.123',                   -- Gmail 邮件帐号密码

    @use_default_credentials = 0,

    @enable_ssl = 1;                          -- 启用SSL 通讯加密

 

-- 数据库邮件配置文件

EXEC msdb.dbo.sysmail_add_profile_sp

    @profile_name = @profile_name;

   

-- 把数据库邮件帐号添加到邮件配置文件中

EXEC msdb.dbo.sysmail_add_profileaccount_sp

    @profile_name = @profile_name,

    @account_name = @account_name,

    @sequence_number = 1;

 

-- 授予任意用户使用数据库邮件配置文件的权限

EXEC msdb.dbo.sysmail_add_principalprofile_sp

    @principal_name = N'guest',

    @profile_name = @profile_name,

    @is_default = 0;

 

 

-- =================================================

-- 发送邮件

-- =================================================

EXEC msdb.dbo.sp_send_dbmail

    @profile_name = @profile_name,

    @recipients = N'GmailTest@gmail.com',      -- 收件人地址

    @subject = N'test mail from database',     -- 邮件主题

    @body = N'this is a test mail';            -- 邮件内容

 

 

-- =================================================

-- 删除配置

-- =================================================

/* --

DECLARE

    @account_name sysname,

    @profile_name sysname;

SELECT

    @account_name = N'GmailTest@gmail.com',

    @profile_name = N'gmail';

 

-- 从邮件配置文件中删除数据库邮件帐号

EXEC msdb.dbo.sysmail_delete_profileaccount_sp

    @profile_name = @profile_name,

    @account_name = @account_name;

   

-- 删除数据库邮件帐号

EXEC msdb.dbo.sysmail_delete_account_sp

    @account_name = @account_name;

 

-- 删除数据库邮件配置文件

EXEC msdb.dbo.sysmail_delete_profile_sp

    @profile_name = @profile_name;

 

 

-- 禁用数据库邮件功能

EXEC sys.sp_configure 'Database Mail XPs', 0;

RECONFIGURE;

 

EXEC sys.sp_configure N'show advanced options', 0

RECONFIGURE;

-- */

发表于 @ 2008年12月13日 14:12:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:将指定的表/视图中的数据导出为 html 文件 | 新一篇:令人郁闷的“事务中的变量赋值错误”

  • 发表评论
  • 评论内容:
  •  
Copyright © zjcxc
Powered by CSDN Blog