Coldfusion CFMAIL&;CfMailPart自定义标记

Coldfusion CFMAIL&;CfMailPart自定义标记,coldfusion,cfmail,Coldfusion,Cfmail,我正在为CFMAIL编写自定义标记。我需要以不同于标准CFMAIL的方式处理某些电子邮件。我用下面的帖子作为出发点- 以前 <cfmail to="no@example.com" from="no@test.com" subject="This is only a test"> <cfmailparam name="Importance" value="high"> hello world</cfmail> 你好,世界 在自定义标记之后 <cf_e

我正在为CFMAIL编写自定义标记。我需要以不同于标准CFMAIL的方式处理某些电子邮件。我用下面的帖子作为出发点-

以前

<cfmail to="no@example.com" from="no@test.com" subject="This is only a test">
<cfmailparam name="Importance" value="high">
hello world</cfmail>

你好,世界
在自定义标记之后

<cf_email to="no@example.com" from="no@test.com" subject="This is only a test">
<cf_emailparam name="Importance" value="high">
hello world</cf_email>

你好,世界
自定义CFMAIL和CFMAILPARAM的一切都正常工作,但我的问题是如何处理“CFMAILPART”。在新标记中使用现有的CFMAILPART时,CF抛出一个错误

<cf_email to="no@example.com" from="no@test.com" subject="This is only a test">
<cf_emailparam name="Importance" value="high">
    <cfmailpart type="text">Text</cfmailpart>
    <cfmailpart type="html">HTML</cfmailpart></cf_email>

正文
HTML
详细信息:标记必须嵌套在cfmail标记中

消息:标记cfmailpart的上下文验证错误

我的想法出人意料,但找不到任何帮助。任何帮助或出发点都将不胜感激


提前感谢。

编辑:虽然这将使它能够使用自定义标记工作,但John Whish使用cfc的解决方案更加灵活

您可能需要创建一个
cf_emailpart
自定义标记,原因与创建
cf_emailparam
标记的原因相同
cfemailparam
必须包含在
cfmail
标记中

<cf_email to="no@example.com" from="no@test.com" subject="This is only a test">
    <cf_emailparam name="Importance" value="high">
    <cf_emailpart type="text">Text</cf_emailpart>
    <cf_emailpart type="html">HTML</cf_emailpart>
</cf_email>
然后,您需要将其添加到
cf_电子邮件
自定义标记文件中,在输出
cfmailparam
标记的部分之后,以及
cfmail
标记中

<cfif isDefined("thisTag.emailPart")>
    <cfloop array="#thisTag.emailPart#" index="attrCol">
        <cfmailpart attributecollection="#attrCol#" >
    </cfloop> 
 </cfif>


我还没有测试过这段代码,但我认为这是您必须走的方向

编辑:虽然这将使它能够使用自定义标记工作,但John Whish使用cfc的解决方案更加灵活

您可能需要创建一个
cf_emailpart
自定义标记,原因与创建
cf_emailparam
标记的原因相同
cfemailparam
必须包含在
cfmail
标记中

<cf_email to="no@example.com" from="no@test.com" subject="This is only a test">
    <cf_emailparam name="Importance" value="high">
    <cf_emailpart type="text">Text</cf_emailpart>
    <cf_emailpart type="html">HTML</cf_emailpart>
</cf_email>
然后,您需要将其添加到
cf_电子邮件
自定义标记文件中,在输出
cfmailparam
标记的部分之后,以及
cfmail
标记中

<cfif isDefined("thisTag.emailPart")>
    <cfloop array="#thisTag.emailPart#" index="attrCol">
        <cfmailpart attributecollection="#attrCol#" >
    </cfloop> 
 </cfif>


我还没有测试过这段代码,但我认为这是您必须走的方向

它必须是自定义标记吗?在我看来,这将是更简单的包装在氟氯化碳。比如:

<cfcomponent output="false">

    <cffunction name="init" access="public" returntype="any" output="false">
        <cfreturn this>
    </cfunction>

    <cffunction name="sendEmail" access="public" returntype="void" output="false">
        <cfargument name="to" required="true">
        <cfargument name="from" required="true">
        <cfargument name="subject" required="true">
        <cfargument name="importance" required="true">
        <cfargument name="htmlContent" required="true">
        <cfargument name="textContent" required="true">

        <!--- do a check here to see if in production something like--->
        <cfif ListFirst(CGI.SERVER_NAME, ".") neq "www">
            <!--- override the to email address or whatever here --->
            <cfset to = "foo@development.local">
        </cfif>

        <cfmail to="#to#" from="#from#" subject="#subject#">
            <cfmailparam name="Importance" value="#importance#">
            <cfmailpart type="text/plain">#textContent#</cfmailpart>
            <cfmailpart type="text/html">#htmlContent#</cfmailpart>
        </cfmail>
    </cffunction>

</cfcomponent>

#文本内容#
#htmlContent#
然后,您可以通过以下方式进行呼叫:

<cfset Mailer = new Path.To.Component()>
<cfset Mailer.sendEmail(
    to="foo@somewhere.com",
    from="bar@somewhere.com",,
    subject="An Email",
    importance="high",
    htmlContent="<p>Hello!</p>,
    textContent="Hello!"
)>


它必须是自定义标记吗?在我看来,这将是更简单的包装在氟氯化碳。比如:

<cfcomponent output="false">

    <cffunction name="init" access="public" returntype="any" output="false">
        <cfreturn this>
    </cfunction>

    <cffunction name="sendEmail" access="public" returntype="void" output="false">
        <cfargument name="to" required="true">
        <cfargument name="from" required="true">
        <cfargument name="subject" required="true">
        <cfargument name="importance" required="true">
        <cfargument name="htmlContent" required="true">
        <cfargument name="textContent" required="true">

        <!--- do a check here to see if in production something like--->
        <cfif ListFirst(CGI.SERVER_NAME, ".") neq "www">
            <!--- override the to email address or whatever here --->
            <cfset to = "foo@development.local">
        </cfif>

        <cfmail to="#to#" from="#from#" subject="#subject#">
            <cfmailparam name="Importance" value="#importance#">
            <cfmailpart type="text/plain">#textContent#</cfmailpart>
            <cfmailpart type="text/html">#htmlContent#</cfmailpart>
        </cfmail>
    </cffunction>

</cfcomponent>

#文本内容#
#htmlContent#
然后,您可以通过以下方式进行呼叫:

<cfset Mailer = new Path.To.Component()>
<cfset Mailer.sendEmail(
    to="foo@somewhere.com",
    from="bar@somewhere.com",,
    subject="An Email",
    importance="high",
    htmlContent="<p>Hello!</p>,
    textContent="Hello!"
)>


你使用的是什么版本的ColdFusion?我看到代码是从2011年开始的。此人可能是在CF 9上这样做的。为
cfmail
编写自定义标记的用例是什么?看起来你并没有做任何不同的事情。只是对自定义标签说不。我正在使用自定义标签指向某个第三方的CFMAIL来处理点击率、下降等。我们有几十个以上的CFMAIL实例,计划现在将一些实例移动到第三方,然后最终移动更多实例。不是所有的CFMAIL都指向第三方,这就是为什么我想使用CFMAIL和CFU电子邮件的原因。您使用的是什么版本的ColdFusion?我看到代码是从2011年开始的。此人可能是在CF 9上这样做的。为
cfmail
编写自定义标记的用例是什么?看起来你并没有做任何不同的事情。只是对自定义标签说不。我正在使用自定义标签指向某个第三方的CFMAIL来处理点击率、下降等。我们有几十个以上的CFMAIL实例,计划现在将一些实例移动到第三方,然后最终移动更多实例。不是所有的CFMAIL都会指向第三方,这就是为什么我想使用CFMAIL和CFU电子邮件的原因。我甚至比我自己更喜欢这种解决方案。CFC比定制标签灵活得多。不一定。CFC和定制标签只是解决了不同的问题。有时一个人比另一个人更合适。在这种情况下,CFC会更好。我甚至比我自己更喜欢这种解决方案。CFC比定制标签灵活得多。不一定。CFC和定制标签只是解决了不同的问题。有时一个人比另一个人更合适。在这种情况下,CFC会更好。