如何使用 ColdFusion 将 cfm 文件作为电子邮件正文发送?
我有一个旧应用程序,其中 email.cfm
文件与 cfmail
标签一起使用来发送电子邮件:
<cfmail from="[email protected]" to="[email protected]" subject="New e-mail!">
// lots of HTML
</cfmail>
现在我想针对 ColdFusion 更新它模型胶3。我想使用控制器中的mail
对象发送它,并在正文中包含一个CFM页面:
var mail = new mail();
mail.setFrom("[email protected]");
mail.setTo("[email protected]");
mail.setSubject("New e-mail!");
mail.setBody( ** SOME CFM FILE ** );
mail.send();
有人知道我该怎么做吗?
I have a legacy application where an email.cfm
file is used with a cfmail
tag to send e-mail:
<cfmail from="[email protected]" to="[email protected]" subject="New e-mail!">
// lots of HTML
</cfmail>
Now I'd like to update it for ColdFusion Model Glue 3. I want to send it using a mail
object in the controller, and include in the body a CFM page:
var mail = new mail();
mail.setFrom("[email protected]");
mail.setTo("[email protected]");
mail.setSubject("New e-mail!");
mail.setBody( ** SOME CFM FILE ** );
mail.send();
Does anybody have any idea how I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在
cfsavecontent
块中呈现要通过电子邮件发送的内容,然后在电子邮件中使用该内容,例如:请参阅 http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d57.html
You can render the content you want to email in a
cfsavecontent
block and then use that in the email, like:See http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d57.html
调用 CFC 将其分配给变量,例如 cfset request.emaiBody = cfc.function()。然后将其放入 setBody 标签中。
Call the CFC assigning it to a variable, like cfset request.emaiBody = cfc.function(). Then just put it in your setBody tag.
OP 确信使用 CFML,但要回答最初提出的问题:
OP was convinced to use CFML, but to answer the question as it was initially asked:
我最终遵循了 Henry 在评论中的建议,创建了一个基于 CFML 的 CFC:
Dave Long 的建议也很好,即使用
创建组件,然后将代码包装在中
标签。这使您能够在没有 cfscript 等效项的情况下回退到 CFML,或者使用 CFML 更容易:I ended up following Henry's advice in the comments and created a CFML-based CFC:
Dave Long's suggestion is also good, which is to create components using
<cfcomponent>
, then wrapping the code in<cfscript>
tags. This gives you the ability to fall back to CFML in case the there is no cfscript equivalent or it's easier to do with CFML: