Coldfusion 2016 在使用 cfscript mail() 时如何包含模板?

Coldfusion 2016 how to include template when using cfscript mail()?

我尝试使用基于标签的代码完成的一个简单示例:

<cfmail
   to="someone@x.com"
   from="someone@y.com"
   subject="howdy"
   type="html">
      <cfinclude template="path/to/emailtemplates/sometemplate.htm"/>
</cfmail>

我已经使用 cfscript 尝试了各种解决方案,但遇到了障碍。我以为这样就可以了,可惜不行

savecontent variable="mailBody" {
  include "path/to/emailtemplates/sometemplate.htm";
};
mail = new mail();
mail.setTo( "someone@x.com" );
mail.setFrom( "someone@y.com" );
mail.setSubject( "howdy!" );
mail.setType( "HTML" );
mail.setBody( mailBody );
mail.send();

我们不会发送多部分电子邮件 - 只是 HTML。有没有办法在脚本中执行此操作?

问题是,在 cfinlcude 中,您将无法包含 HTML 文件。看起来您将需要 FileRead() 函数的帮助而不是 include.

mailBody=FileRead('absolute/path/to/emailtemplates/sometemplate.htm' [, charsetIfNeeded]);

要使 FileRead 正常工作,您应该提供服务器上磁盘上或内存中文本文件的绝对路径。

不确定这是否回答了最初的问题,但在 coldfusion 10 中我曾经能够告诉 CF 处理除 cfm 之外的其他文件。在您的应用程序中使用此行:

<cfset THIS.compileextforinclude = "htm" />