Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

cfmail in custom tag issue

<cf_call email ="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}">

now in my Custom tag, call.cfm

<cfmail attributecollection="#attributes.email#">

i get an error

The attributeCollection attribute in the cfmail tag can only be a structure.

what seems to be wrong, i find nothing
Avatar of gdemaria
gdemaria
Flag of United States of America image

you are passing "attributes.email"  which is not a structure but a single value for the email addresss.  

I think you want...

<cfmail attributecollection="#attributes#">

not

<cfmail attributecollection="#attributes.email#">
Avatar of Coast Line

ASKER

but from custom tag i am referring the email one, i do have other attributes but that will certainly going to create a problem
or either i just pass it as:

<cfmail attributecollection="#email#">

:?
attributeCollection requires a structure, usually one of the variable scopes such as FORM, attributes, etc.    If you only want to use one value, then you need to remove attributeCollection and specify that value

<cfmail from="#attributes.email#"

.... but then you have to specify all required parameters such as TO, SUBJECT, etc...


This is not valid because #email# is not a collection of values, it is a single value..
<cfmail attributecollection="#email#">
there might be some way of passing the info
Let's step back and start from the top because I think we are talking about different things.

When you use your cf_mail custom tag you are passing a bunch of variables to it individually..

<cf_call email ="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}">


Now, inside your custom tag you are receiving these all as attribute scope variables.  You want to pass these to your CFMAIL call, so you would use the attribute collection with the ATTRIBUTES scope..  that will pass along everything you received into your CF_MAIL custom tag...

<cfmail attributecollection="#attributes#">


What is wrong with that?  


I recommend doing it differently though.  I think inside your CF_MAIL tag you should hard code each attribute.   What if someone passed junk to your CF_MAIL custom tag, you don't want to automatically pass that along to your CFMAIL tag it would throw an error.

Pass along all the values from your form submit..
<cf_mail attributeCollection="#form#">

Inside that, call CFMAIL with each one..

<cfmail from="#attributes.from#"   to="#attributes.to#" subject="#attributes.subject#">
   ... etc...


That is the way I suggest doing it..   it keep the CFMAIL call clean
okay now it is like this


<cf_call email ="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}"
logfile="yes" attached="yes">

now u see i have other attributes being send to,

why i m trying to use attributes.email is because it should refer to that passed one value

i hope i am clear now
Ok, I see what you are doing... you are creating a structure in the variable EMAIL

I think it should be..

--- create email as a structure of values...
<cfset email ="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}" >

... pass the structure as a collection
<cf_mail attributeCollect="#email#"  logfile="yes" attached="yes">
u are making my custom tag wrong its not

<cf_mail, it is <cf_call mail="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}">
So CF_CALL requires a parameter called "mail" which is a structure?

If true, then I would go back to what you had suggested...

<cfmail attributecollection="#attributes.email#">

What happens when you do this?  

Sorry, I didn't realize that "email"  was a structure of values being passed as a structure to the custom tag

You can do a dump of the variable to make sure it looks good before..


<cfdump var="#attributes.email#">
<cfmail attributecollection="#attributes.email#">
i did dumped, works weel shows good information in dump but when it goes to cfmail tag it breaks
what is the error message?
ok, now i got it resolved here it is:

<cf_call email ="#{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}#">

<cfmail attributecollection="#attributes.email#">

and it worked, it expects the value to be wrapped with ##, do not why
> and it worked, it expects the value to be wrapped with ##, do not why

It should not have appeared correctly in the dump then..

You were probably seeing all the values in one row of the table cell, each row of the dump should have had one variable and one value
means

well i have still to dump it after i pass it as ##

i have dumped it without hashes and it shows correct order  passing it as structure

so now i will dump again as i am now passing it by ## around it and see what does it shows me now and then i will share my findings
ok, now is the issue again in CF 8.0.1

I get the following Error


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

The CFML compiler was processing:

 
while in CF 9, It works Fine
<cfset email = structNew()>
<cfset email ="{to='test@test.com',
      from='test@test.com',
      subject='Error reported',
      server='mail.test.com',
      username='test@test.com',
      password='test'}" >

--- make sure you have a good, valid structure ----
<cfdump var="#email#">

--- pass the structure
<cf_mail email="#email#"  logfile="yes" attached="yes">


perhaps you can include an image of the cfdump result as it shows INSIDE the cf_mail custom tag
I forgot to add a note, perhaps the difference between CF 8 and 9 is the ability to do in-line structure definition.  You could get around that by creating the structure into a variable first???
 (see code above)
alright, i have found some code from Dan's Site which is converting the values of the following into this

<cf_call email="to=test@test.com,from=test@test.com,subject=Error reported,
            server=mail.test.com,username=test@test.com,password=test,type=html" log="yes">

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

now when i dump it the

<cfdump var="#emailSetting#">, it shows the dump correctly, but when i pass it to the cfmail tag, it says smtp server is not defined

no, i have agreed on ur points than cf9 and cf8 syntaxes differ, but for this tag, i want to use one value so it should be compatible with both, i hope u agree on my points

thanks
any update on this
Oh, I thought your last post was the resolution!

The code you showed is taking a list and parsing it.   That shows that you are not passing a STRUCTURE to the custom tag, but you are just passing a list.

Define your structure like this...

 <cfset email = structNew()>
 <cfset email.to = "">
 <cfset email.from = "">
 <cfset email.subject = "">
 <cfset email.server = "">
 <cfset email.username = "">
 <cfset email.password = "">
 
Then pass the email structure to your custom tag
> <cfdump var="#emailSetting#">, it shows the dump correctly, but when i pass it to the cfmail tag, it says smtp server is not defined

OR you can leave the code as you have it now (passing a list and then parsing the list)  but when you pass it to the CFMAIL tag you have to use the emailSetting structure

<cfmail attributecollection="#emailSetting #">
yes after parsing the list and it converts the parsed list into structure, i do the same as you did in ur last post, but it picks everything except the server, says smtp server not defined
any update @gd, or we should use a different approach which works on on both servers, CF 8 adn CF9
Can you post the code from the approach you're currently using.

I think this is the way to define your structure before passing it...

<cfset email = structNew()>
 <cfset email.to = "">
 <cfset email.from = "">
 <cfset email.subject = "">
 <cfset email.server = "">
 <cfset email.username = "">
 <cfset email.password = "">

Not sure what you've tried and not.  But if you can show your current code, I could play with it a bit..
ok my call is like this:

<cf_ckmail iEmail="to=test@test.com,from=test@test.com,subject='Error reported',
            server=mail.test.com,username=test@test.com,password=test,type=html"
      iLog="yes">

now my custom tag

<cfparam name="attributes.iLog" default="no">
      <cfparam name="attributes.iEmail" default="">

<cfif attributes.iEmail NEQ "">
<cfset emailSetting = StructNew()>
                  <!--- loop our query string values and set them in our structure --->
                  <cfloop list="#attributes.iEmail#" index="key" delimiters=",">
                      <cfset emailSetting["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))>
                  </cfloop>
                  <cfmail attributecollection = "#emailSetting#">
                        Errors has been reported by the user
                        <br>
                        <cfif attributes.iLog EQ "Yes">
                              The Log File has been created/appended for this Error too
                        </cfif>
                  </cfmail>
                  </cfif>
</cfif>
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
with real email, it works but only it fails when it goes to the custom tag i wonder why?
Hi @gd, Let's Get back to this Question so we can try again, I will share my Whole Code with you so we can come to some kind of Solution
Hi @gd, Let's Get back to this Question so we can try again, I will share my Whole Code with you so we can come to some kind of Solution

Another Call for @gd so we can come to any solution and close this question properly rather than an in complete answer
Should we try or not, or should i delete this question
still working on this?  Wow!

Curious - post your code and we'll see what's up
@gd, should i close
Accepting the answer as it still does not provide me real answer but to close one what i am trying to do, hopefully i can find answer from somewhere else, for thanks for your help