简体   繁体   English

如何在SQL Server中配置和运行数据库邮件

[英]How to configure and run database mail in SQL Server

How to enable and run database mail in SQL Server 2008? 如何在SQL Server 2008中启用和运行数据库邮件? I know that it need to 我知道这需要

  • Enabling Service Broker 启用服务代理
  • Configuring SMTP (a Mail server is needed) 配置SMTP(需要邮件服务器)
  • Using configuration stored procedure 使用配置存储过程

I don't know what's the relation between application and database mail. 我不知道应用程序和数据库邮件之间有什么关系。

Actually how to enable database mail for a RollBack and Commit Transaction ? 实际上,如何为回滚提交事务启用数据库邮件? (not for all SP , just for some of them) (并非针对所有SP,仅针对其中一些)

Update : database mail is a service which automatically sends mail (or sms) to a person which you specify in the configuration. 更新 :数据库邮件是一项自动将邮件(或短信)发送给您在配置中指定的人员的服务。 You can specify that this event (sending mail) where and when fired. 您可以指定在何时何地触发此事件(发送邮件)。 So I want to see how can I configure this. 所以我想看看如何配置它。

I cannot think of any way to configure db mail to send for every rollback or transaction, that would be a little overkill, and it sounds like you want to be selective about it anyways. 我想不出任何方法来配置db邮件以针对每个回滚或事务发送,这有点过头了,而且听起来您无论如何都要对此有所选择。

What you can do though is add a call to the email sp after each commit / rollback in your stored procedures. 但是,您可以做的是在存储过程中的每次提交/回滚之后,向电子邮件sp添加一个调用。 Here's a quick example: 这是一个简单的示例:

BEGIN TRAN
-- sql operations here
COMMIT

-- send email
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DB Alerts',
@recipients = 'you@yourdomain.com',
@body = 'Commit completed for ...',
@subject = 'SQL Commit/Rollback event';

You can read more about the parameters for sp_send_dbmail here: http://msdn.microsoft.com/en-us/library/ms190307.aspx 您可以在此处阅读有关sp_send_dbmail的参数的更多信息: http : //msdn.microsoft.com/zh-cn/library/ms190307.aspx

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM