如何发送带有存储过程结果的电子邮件
我想知道是否有办法让 SQL Mail 自动发送带有附件的电子邮件 某些查询已完成。假设我想运行一个查询,完成后发送结果以及 通过 SQL Mail 作为报告附件。这可能吗?如果可以,有人知道我可以在哪里找到吗? 有关如何执行此操作的信息?
I'm wondering if there is a way to have SQL Mail automatically send an email with an attachment when a
certain query is complete. Say I want to run a query, and when it's finished, send the results as well as an
attachment as a report via SQL Mail. Is this possible, and if so, does anyone have any idea where I can find
information on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用哪个数据库?我知道 MySQL 可以将已编译的用户定义函数 (UDF) 加载到其中以执行自定义操作。在 Oracle 上,您可以加载可使用触发器调用的 jar 文件。在 MS SqlServer 上,您可以加载可从触发器调用的 .net 二进制文件。它可以完全访问 .net 框架,其中包括邮件。
更新
在 SqlServer 2005 上,您可以将 .net 程序集加载到数据库中。这是一个简单的教程链接。它使您能够调用 .net 代码(例如 .dll),并且该代码将由数据库执行。在示例中,它仅在数据库控制台调用“hello world”,但您可以更改 hello world 程序以写入文件或发送电子邮件。在您的情况下,您需要创建一个发送电子邮件的例程。在数据库中,您可以创建一个监听表的触发器。当您完成查询时,它可以插入到触发触发器的表中。然后触发器将调用您的 .net 程序集并发送电子邮件。您可以编写函数来接受输入参数,这些参数可以是您提到的结果或其他任何内容。
Which database are you using? I know that MySQL can have compiled user defined functions (UDF) loaded into it to perform custom actions. On Oracle, you can load jar files which can be called using triggers. On MS SqlServer, you can load a .net binary which can be called from triggers. It has full access to the .net framework which would include mail.
update
On SqlServer 2005 you can load a .net assembly into the database. Here is a simple tutorial link. What it enables you to do is to call your .net code (say a .dll) and that code will be executed by the database. In the example it only calls "hello world" at the database console, but you could change your hello world program to write to a file or send out an email. In your case you would want to create a routine which sends out emails. In the database you can create a trigger which listens to a table. When you finish your query, it can insert into that table firing the trigger. The trigger will then call your .net assembly and send the email out. You can write your function to take in input arguments which can be results you mentioned or anything else.