This content has been marked as final. Show 6 replies
with CF8 you can specify arguments to cfmail inside an
so if your cfmail function is is a cfc method, you can invoke the cfc in
cfscript with createobject(), then access the cfmail method and pass it
the attributeCollection structure as argument...
yea.............. using 6.1 though....
just add a mail method into .../WEB-INF/cftags/component.cfc
<cffunction name="writeMail" returntype="boolean" output="false" access="public" hint="i provide a simple wrapper for CFMAIL calls in components and cfscript">
<cfargument name="message" type="any" required="true" hint="Message body to cfmail: can be a string or complex structure, like CFDUMP">
<cfargument name="subject" type="string" required="true" hint="Mail subject">
<cfargument name="to" type="string" required="true" hint="Mail to">
<cfargument name="from" type="string" required="true" hint="Mail from">
<cfargument name="cc" type="string" required="true" hint="Mail cc list">
<cfargument name="type" type="string" required="true" hint="Mail type: text, plain or html">
<cfset var mailSuccessful = TRUE>
<!--- if not a simple value, must set mail type to HTML since we're going to CFDUMP complex data --->
<cfif NOT IsSimpleValue(arguments.message)>
<cfset arguments.type = "html">
<cfmail to="#trim(arguments.to)#" from="#trim(arguments.from)#" cc="#trim(arguments.cc)#" type="#trim(arguments.type)#" subject="#trim(arguments.subject)#"><cfif NOT IsSimpleValue(arguments.message)><cfdump var="#arguments.message#"><cfelse>#arguments.message#</cfif></cfmail>
<cfset mailSuccessful = FALSE>
<cfset mailSuccessful = FALSE>
ummmm . yea - am I missing or not understanding something? that looks almost exactly what I have already...
Maybe I did not explain my case clearly enough... what I am trying to do is avoid extra required attributes. I want to be able to pass the function as much or as little as required, i.e. just the to and type attribute, or possibly all the attributes - bcc...
So basically none of the arguments [but the 'to' attrib] can be required. Really something that I would love to end up with is something like this:
> So basically none of the arguments [but the 'to' attrib] can be required.
> Really something that I would love to end up with is something like this:
> <cfmail #mailargs# >
And as Azadi said: it can't be done with CFMX6.1. So you can want to do it
as much as you like, but that doesn't change the fact *you can't*. One
cannot build a CFML tag like that, with runtime arguments providing the
"body" of the tag. The source code has tobe syntactically correct *at
compile time*. Your variable doesn't exist until runtime. That's it.
There is no way around that.
So either upgrade to CF8, or... write a wrapper function which caters for
all permutations of required / optional arguments.
Or just stick with the tag.
What's the need to do it in <cfscript>? <cfmail> (esp if one considers
<cfmailpart> and <cfmailparam>) is one of the few bits of CF functionality
that actually *lends itself* to being implemented as a tag.