[英]Can I use SQL Database Mail to send an HTML page as a message via its URL, the same way you can with the CDO.Message object in VBScript?
I'm working on a project that uses an SQL trigger to fire off emails when certain fields are updated, and the emails need to be in HTML format with complex design, something that would be very difficult to pull off using the @body_format = 'HTML' command. 我正在开发一个项目,该项目使用SQL触发器在更新某些字段时触发电子邮件,并且电子邮件必须采用具有复杂设计的HTML格式,使用@body_format =' HTML”命令。 As it stands, the only articles I've found have been about formatting the body of the message using HTML in the SQL code, but I'm looking to reference a URL and send the corresponding page as an HTML body.
就目前而言,我发现的唯一文章是有关在SQL代码中使用HTML格式化消息正文的,但是我希望引用URL并将相应的页面作为HTML正文发送。
I know that there's a way in VBScript to generate an HTML page and send it as a message by referencing its URL by using the .CreateHTMLBody command on a CDO.Message object, and that's the kind of functionality I'm looking for in SQL. 我知道VBScript中存在一种方法,可以通过使用CDO.Message对象上的.CreateHTMLBody命令来引用HTML的URL来生成HTML页面并将其作为消息发送,这就是我正在SQL中寻找的功能。
I'm using Microsoft SQL Server Management Studio. 我正在使用Microsoft SQL Server Management Studio。
Short answer no.... Long answer yes :) 简短的回答不是。...简短的回答是:)
Ways to do it. 做到的方式。
1) If you build your page on the web then just store the html
in a table and look it up. 1)如果您在网络上构建页面,则只需将
html
存储在表中并进行查找。 If it needs to change all of the time build the html
in a template manner that you put some crazy text in certain locations ( @@FIRSTNAME@@
) that you will REPLACE
with your dynamic content and all of a sudden you are good to go and not too much difficult handling of the html. 如果需要始终更改,请以模板方式构建
html
,然后在某些位置( @@FIRSTNAME@@
)放置一些疯狂的文本,以REPLACE
动态内容,突然之间,您就可以开始使用了并没有太多困难的HTML处理。
2) Build a CLR with your VB code. 2)用您的VB代码构建CLR。 this is more complex but on a plus side you can also send your message directly from here through an SMTP gateway and I have had issues where DB mail has retried and sent way too many messages to public users so I don't use it for heavy emailing at all!
这比较复杂,但从正面来看,您也可以通过SMTP网关直接从此处发送消息,而我遇到了数据库邮件重试并向公共用户发送太多消息的问题,因此我不会将其用于繁重的工作完全用电子邮件发送!
3) Build a SSIS package and place your VB script inside a script task to generate the email, create a SQL agent job, then use tSQL to execute that job. 3)构建一个SSIS包,并将您的VB脚本放入脚本任务中以生成电子邮件,创建一个SQL代理作业,然后使用tSQL执行该作业。
4) Call your VBScript directly xp_CmdShell
or some other method straight from the trigger. 4)直接从触发器中直接调用
xp_CmdShell
或其他方法来调用VBScript。 This one is definitely the scariest impact from a security perspective but if you lock down access and only allow for certain user(s) it is not so so bad...... Here is an article that I haven't read in full but looks to be very exhaustive on the subject. 从安全角度来看,这绝对是最可怕的影响,但是如果您锁定访问权限并仅允许某些用户访问,那就还不算太糟……这是我没有完整阅读的文章但在这个问题上看起来非常详尽。 https://www.simple-talk.com/sql/database-administration/the-posh-dba-solutions-using-powershell-and-sql-server/
https://www.simple-talk.com/sql/database-administration/the-posh-dba-solutions-using-powershell-and-sql-server/
Added benefit to using methods > 1. You can create a threaded application to send several thousand messages very quickly if needed! 使用方法>的另一个好处是:1.如果需要,您可以创建一个线程化的应用程序以非常快速地发送数千条消息! I literally send 2,000 messages from my DB server to Exchange server in under a minute because of a threaded clr.....
由于线程clr,我在一分钟内从我的数据库服务器向Exchange服务器发送了2000条消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.