Hi I am trying to use cfmail in cfscript blocks... which I
have done and works, now I just need to get it tuned a little more
friendlier...
what I would like to do is be able to dynamically specify the
<cfmail> attributes in the cfscript tag i.e.
<cfscript>
cfmail('from="email@dot.com" to="email@dot.com" subject="this
is the subject" type="html"','content');
<cfscript>
and then basically write the mail function like this
<function.....
<cfmail #parm1#>#parm2</cfmail>
...function>
- which of course does not work...
How important is this??? not really, I just would rather not
break out of the cfscript blocks to send mail!
with CF8 you can specify arguments to cfmail inside an
attributeCollection structure...
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...
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">
<!--- 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">
</cfif>
<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>
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.