Etiqueta personalizada de ColdFusion que llama a cfmail como attibuteCollection y arroja un error

I am trying this on CF 8.0.1, but failing. I am trying to pass a custom value to the custom tag, like this:

<cf_call ckmail="#{to='test@test.com',from='test@test.com',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}#">

In the custom tag call.cfm i have the following:

<cfparam name="attributes.ckmail" default="">
<cfmail attributecollection = "#attributes.ckmail#">

El error que recibo es:

Invalid CFML construct found on line 11 at column 18. ColdFusion was looking at the following text: {

It is working good in CF9, but in CF8.0.1 (or previous version) it is failing with the above message.


Code Update as of July 18th 2012


I tried using dan's Code but now i am facing a different issue, In my Custom Tag i am using like this

       <cfset emailSetting = StructNew()>
   <!--- loop our query string values and set them in our structure --->
   <cfloop list="#attributes.ckmail#" index="key" delimiters=",">
     <cfset emailSetting["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))>
   </cfloop>
   <cfdump var="#emailSetting#"><cfabort>
       <cfmail attributecollection = "#emailSetting#"> 

The above are my settings in the custom tag, i called it from my code as

       <cf_call ckmail="to=i@test.com,from=test@domain.com,subject='Error reported',
    server=mail.domain.com,username=test@domain.com,password=tes@,type=html">

The error now i am getting is "smtp" server is not defined,

if i add smtp details in cfadmin it works, may be it ignores values in the field i typed but it shows error when there is no smtp settings defined in the cfadmin too.

preguntado el 04 de julio de 12 a las 10:07

3 Respuestas

The implicit structure should work in CF8.0.1 as you have it.

You can of course use code like the following to build your structure using the structNew() function:

<cfset mailArgs             = StructNew() />
<cfset mailArgs.to          = 'test@test.com' />
<cfset mailArgs.from        = 'test@test.com' />
<cfset mailArgs.subject     = 'Error reported' />
<cfset mailArgs.mailserver  = 'mail.domain.com' />
<cfset mailArgs.username    = '1234' />
<cfset mailArgs.password    = 'tested' />

<cf_call ckmail="#mailArgs#"> 

Can you post a more detailed error report from ColdFusion here so that we can help you find the exact location of the error? Or can you post more of the code?

Respondido 04 Jul 12, 12:07

This is the detailed report i get from the code, My Confusion lies when the CF9 executes this Process and in CF 8 it fails, I see you have declared a Struct in different manner and then Passing it to the cfmail tag, I want it tobe passed along the Custom Tag but do not want to declare separately and the again use the above written code in Custom tag as:<cf_call ckmail="#mailArgs#">, i want to pass the actual written above rather than evaluate it again here - brumoso

You're using the struct literal syntax in the ckmail attribute, which I think has changed behaviour between CF8 and CF9. I'd try creating a struct the old-fashioned way and see if that works.

Respondido 04 Jul 12, 11:07

so using the Structnew() right, Btw i am passing it in Custom tag so bit confused how that will work - brumoso

it will just look like <Cf_call ckmail=ckmail/> It won't have any construtor syntax - that's all done ahead of time. Check out the first answer - Matt's example is pretty clear. - marca un kruger

Hmmm.... I wonder if the pound signs look odd to anyone else in the custom tag call? Stucture notation usually looks like this:

<cfset mystruct = {to='test@test.com',from='test@test.com',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/>

The pound signs would cause CF to try and "do something" to merge the values (like when you do <cfset z = #x+y#/> ... but leaving them off allows CF to "see" the constructor indicators (the curly braces).

But I'm not sure how a custom tag would behave in that instance. Have you tried calling it like so:

<cf_call 
 ckmail={to='test@test.com',from='test@test.com',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/>

Or failing that - as has been suggested - set it up ahead of time as:

<cfset args = {to='test@test.com',from='test@test.com',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/>

Luego llame:

<cf_call ckmail="#args#"/>

See if any of those work eh?

Respondido 04 Jul 12, 15:07

i tried all the way you said here, but still i am facing the same problem, i have updated my question please check, this time i am getting some different error "smtp is not defined" - brumoso

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.