A week or so ago I had an odd error report on the BlogCFC beta. A user had errors using the Send() function on a CFMX 6.1 box, but not 7. The error was a null pointer exception (npe), which are notorious for being hard to debug. (For me anyway.) The error was occurring inside cfmail tags where I rendered the body of the entry. For the life of me I couldn't figure out what was going wrong... until I noticed that I had used cfoutput tags.
You aren't supposed to need cfoutput tags inside a cfmail tag since the cfmail acts like a cfoutput. So this is fine:
<cfmail ...>
#x#
</cfmail>
In fact, earlier in the email I had done exactly that. I had simply forgotte and used cfoutput tags.
What made this odd is that CFMX 7 had no problem with the code at all. It ran just fine. Only CFMX 6.1 threw the NPE. Anyone know why? I'm sure it's something simple.
For those who want to test, this is a simple script I used in both 6.1 and 7:
<cfmail to="whoever@localhost.com" from="whover@localhost.com" subject="oops">
<cfoutput>foo</cfoutput>
</cfmail>
p.s. Guess which popular blogging application will be shipping later today?
Archived Comments
This may not be related but we're getting some very random:
Type: java.lang.NullPointerException
Tag Context:
Stack trace: java.lang.NullPointerException
Errors and did have <cfoutput> on our cfmail wrapper.
In desperation I've removed it but alas, it's too early (or later on a Friday as it were) to tell.
CFMX 7 changed the behavior of CFOUTPUT. You can now safely nest CFOUTPUT tags without using the group attribute and they will be effectively ignored. Since CFMAIL acts essentially as a CFOUTPUT it's certainly related.
Let me see if I can find the release note.
Aaargh! I know I read it somewhere or someone told it to me, but I cannot for the live of me find it.
I wonder if a similar problem would be caused by:
<cfmail ....>
<cfoutput>
<cfinclude template="test.cfm" />
</cfoutput>
</cfmail>
----
test.cfm:
<cfoutput>
test
</cfoutput>
Don't have MX6.1 anywhere to test but if someone out there does ;)
Personally I always take the email I want to send and wrap it in a cfsavecontent first. Then just put that variable into the cfmail tag. There are so many gotchas and quirks with the CFMX line that it's disgusting. They should of never of gone with java and stuck to the c++ code, I bet we be better off.
I've used that approach myself a few times.
As for your last comment, I disagree 100%. :) But, that is a whole other can of worms, so let's leave it be.
I wish Adobe would fix CFOUTPUT some more so that this simple code example would work:
<cfset qTest = queryNew( "id" )>
<cfset queryAddRow( qTest, 1 )>
<cfset querySetCell( qTest, "id", "foo" )>
<cfoutput>
<cfoutput query="qTest">#id#</cfoutput>
</cfoutput>
Hi Ray, no more beard?
Is a CFOUTPUT actually neccessary within a CFMAIL tag or does the CFMAIL tag act as a CFOUTPUT?
I cannot seem to write the correct search term for the answer to this in Google, but it seems from this blog post I do not need an additional CFOUTPUT in my CFMAIL tags...
Nope, you don't need cfoutput.