AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 10190
Accepted
M.S.Nayak
M.S.Nayak
Asked: 2012-01-05 21:14:56 +0800 CST2012-01-05 21:14:56 +0800 CST 2012-01-05 21:14:56 +0800 CST

如何在 SQL Server 2008 中创建和发送邮件?

  • 772

我想从 SQL Server 2008 发送电子邮件。基本步骤是什么?如果有人使用这个设施,你能解释一下吗?

任何帮助将不胜感激。

正如 marc_s 评论的那样,此链接将很有帮助(我也接受了下面的答案) http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from -sql-数据库/

sql-server sql-server-2008
  • 3 3 个回答
  • 43591 Views

3 个回答

  • Voted
  1. Carol Baker West
    2013-05-18T09:05:42+08:002013-05-18T09:05:42+08:00
    1. 在 SSMS 对象资源管理器中,单击管理
    2. 右键单击数据库邮件
    3. 单击配置数据库邮件

    在此处输入图像描述

    4.通过执行以下任务选择设置数据库邮件

    在此处输入图像描述

    5.输入配置文件名称并单击添加

    在此处输入图像描述

    6.输入您的电子邮件帐户的设置。我无法为我公司的电子邮件帐户设置帐户 - 它只是不起作用。但是我在设置我使用的 Gmail 帐户时没有遇到任何问题,这些是您应该用于服务器名称和端口号的参数

    在此处输入图像描述

    无法从 SSMS 发送附件,您必须为此使用 T-SQL:

    EXEC msdb.dbo.sp_send_dbmail
    @profile_name='carol Gmail',
    @recipients='[email protected]',
    @subject='Test email',
    @body='Attachment test',
    @file_attachments='D:\123\pic.jpg'
    
    • 7
  2. Best Answer
    Jason Cumberland
    2012-01-06T08:55:45+08:002012-01-06T08:55:45+08:00

    在管理工作室中配置“管理”下的数据库邮件选项(帐户和配置文件),然后使用 msdb 数据库中的存储过程 sp_send_dbmail。

    http://msdn.microsoft.com/en-us/library/ms190307.aspx

    • 3
  3. Renjith Kumar
    2012-01-05T21:58:53+08:002012-01-05T21:58:53+08:00

    试试下面的 SP。

    CREATE procedure [dbo].[usp_send_cdosysmail]
    @from varchar(500) ,
    @to varchar(500) ,
    @subject varchar(500),
    @body varchar(max) ,
    @smtpserver varchar(25),
    @bodytype varchar(10) 
    as
    declare @imsg int
    declare @hr int
    declare @source varchar(255)
    declare @description varchar(500)
    declare @output varchar(1000)
    exec @hr = sp_oacreate 'cdo.message', @imsg out
    exec @hr = sp_oasetproperty @imsg,
    'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").value','2'
    
    exec @hr = sp_oasetproperty @imsg, 'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").value', @smtpserver 
    
    exec @hr = sp_oamethod @imsg, 'configuration.fields.update', null
    exec @hr = sp_oasetproperty @imsg, 'to', @to
    exec @hr = sp_oasetproperty @imsg, 'from', @from
    exec @hr = sp_oasetproperty @imsg, 'subject', @subject
    
    -- if you are using html e-mail, use 'htmlbody' instead of 'textbody'.
    
    exec @hr = sp_oasetproperty @imsg, @bodytype, @body
    exec @hr = sp_oamethod @imsg, 'send', null
    
    -- sample error handling.
    if @hr <>0 
    select @hr
    begin
    exec @hr = sp_oageterrorinfo null, @source out, @description out
    if @hr = 0
    begin
    select @output = ' source: ' + @source
    print @output
    select @output = ' description: ' + @description
    print @output
    end
    else
    begin
    print ' sp_oageterrorinfo failed.'
    return
    end
    end
    exec @hr = sp_oadestroy @imsg
    
    • -4

相关问题

  • 死锁的主要原因是什么,可以预防吗?

  • 我在索引上放了多少“填充”?

  • 是否有开发人员遵循数据库更改的“最佳实践”类型流程?

  • 如何确定是否需要或需要索引

  • 从 SQL Server 2008 降级到 2005

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何查看 Oracle 中的数据库列表?

    • 8 个回答
  • Marko Smith

    mysql innodb_buffer_pool_size 应该有多大?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    从 .frm 和 .ibd 文件恢复表?

    • 10 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    如何选择每组的第一行?

    • 6 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST
  • Martin Hope
    bernd_k 什么时候应该使用唯一约束而不是唯一索引? 2011-01-05 02:32:27 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve