如何使用 ColdFusion 将 cfm 文件作为电子邮件正文发送?

发布于 2024-12-06 08:59:21 字数 995 浏览 2 评论 0原文

我有一个旧应用程序,其中 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

双马尾 2024-12-13 08:59:21

您可以在 cfsavecontent 块中呈现要通过电子邮件发送的内容,然后在电子邮件中使用该内容,例如:

<cfsavecontent variable="myemail">
...add some HTML, include another file, whatever...
</cfsavecontent> 
<cfscript>
mail.setBody( myemail );
</cfscript>

请参阅 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:

<cfsavecontent variable="myemail">
...add some HTML, include another file, whatever...
</cfsavecontent> 
<cfscript>
mail.setBody( myemail );
</cfscript>

See http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d57.html

樱&纷飞 2024-12-13 08:59:21

调用 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.

甜味超标? 2024-12-13 08:59:21

OP 确信使用 CFML,但要回答最初提出的问题:

var mail = new Mail();
mail.setFrom("[email protected]");
mail.setTo("[email protected]");
mail.setSubject("New e-mail!");
mail.setType("html");
savecontent variable="mailBody" {
  include "email.cfm";
}
mail.setBody(mailBody);
mail.send();

OP was convinced to use CFML, but to answer the question as it was initially asked:

var mail = new Mail();
mail.setFrom("[email protected]");
mail.setTo("[email protected]");
mail.setSubject("New e-mail!");
mail.setType("html");
savecontent variable="mailBody" {
  include "email.cfm";
}
mail.setBody(mailBody);
mail.send();
半步萧音过轻尘 2024-12-13 08:59:21

我最终遵循了 Henry 在评论中的建议,创建了一个基于 CFML 的 CFC:

<cfcomponent>

    <cffunction name="SendMail">
        <cfargument name="from"/>
        <cfargument name="to"/>
        <cfargument name="subject"/>

        <cfmail from="#from#" to="#to#" subject="#subject#">
            <!--- HTML for e-mail body here --->
        </cfmail>
    </cffunction>

</cfcomponent>

Dave Long 的建议也很好,即使用 创建组件,然后将代码包装在 标签。这使您能够在没有 cfscript 等效项的情况下回退到 CFML,或者使用 CFML 更容易:

<cfcomponent>
    <cfscript>
        void function GetData()
        {
            RunDbQuery();
        }
    </cfscript>

    <cffunction name="RunDbQuery">
        <cfquery name="data">
            SELECT * FROM ABC;
        </cfquery>
        <cfreturn data>
    </cffunction>

</cfcomponent>

I ended up following Henry's advice in the comments and created a CFML-based CFC:

<cfcomponent>

    <cffunction name="SendMail">
        <cfargument name="from"/>
        <cfargument name="to"/>
        <cfargument name="subject"/>

        <cfmail from="#from#" to="#to#" subject="#subject#">
            <!--- HTML for e-mail body here --->
        </cfmail>
    </cffunction>

</cfcomponent>

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:

<cfcomponent>
    <cfscript>
        void function GetData()
        {
            RunDbQuery();
        }
    </cfscript>

    <cffunction name="RunDbQuery">
        <cfquery name="data">
            SELECT * FROM ABC;
        </cfquery>
        <cfreturn data>
    </cffunction>

</cfcomponent>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文