• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfmail --> cfscript

Participant ,
Dec 12, 2007 Dec 12, 2007

Copy link to clipboard

Copied

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!


below is the working version....



TOPICS
Advanced techniques

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 13, 2007 Dec 13, 2007

Copy link to clipboard

Copied

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...


---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 13, 2007 Dec 13, 2007

Copy link to clipboard

Copied

yea.............. using 6.1 though....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 13, 2007 Dec 13, 2007

Copy link to clipboard

Copied

i see... tough luck...

---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

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>

<cftry>

<cfif FindNoCase(trim(lcase(arguments.type)),"text,plain,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>

<cfelse>
<cfset mailSuccessful = FALSE>
</cfif>

<cfcatch type="any">
<cfset mailSuccessful = FALSE>
</cfcatch>
</cftry>

<cfreturn mailSuccessful>
</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

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:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

LATEST
> 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.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation