[coldbox 3.8.1] - Very strange behaviour with MailService

I am going insane with what would have to be some of the wierdest behaviour I’ve ever come across.

I’ve had a mail service running fine… made a few changes to it recently to get it working inside a thread and try/catch block… was working OK, then started getting an error that the newMail object couldn’t be found when attempting to work with it… tried to dump/abort out the newMail object, and the process worked fine and emails sent… (didn’t dump or abort… which was wierd). But if I remove the writeDump();abort;, it works fine… Have been going in circles on this all day.

Here is the email send script"

`

sendEmail = mailService.newMail(

from = attributes.signature.getEmailAddress(),

to = Application.settings.testemail,

subject="#attributes.prc.org.getName()# - Membership Renewal",

type = “html”

);

sendEmail.addMailPart(charset=‘utf-8’,type=‘text/plain’,body=attributes.Renderer.renderLayout(layout=“email/signatureEmail”, args={rc=attributes.rc}));

sendEmail.addMailPart(charset=‘utf-8’,type=‘text/html’,body=attributes.Renderer.renderLayout(layout=“email/signatureEmail”, args={rc=attributes.rc}));

sentEmail = mailService.send(sendEmail);

`

I get error that sendEmail doesn’t exist at first sendEmail.addMailPart etc… So I tried adding writeDump (see below) expecting it to dump out writeDump, or tell me it wasn’t there, BUT the emails just sent fine… don’t even dump and abort…

`

sendEmail = mailService.newMail(

from = attributes.signature.getEmailAddress(),

to = Application.settings.testemail,

subject="#attributes.prc.org.getName()# - Membership Renewal",

type = “html”

);

writeDump(sendEmail);abort;

sendEmail.addMailPart(charset=‘utf-8’,type=‘text/plain’,body=attributes.Renderer.renderLayout(layout=“email/signatureEmail”, args={rc=attributes.rc}));

sendEmail.addMailPart(charset=‘utf-8’,type=‘text/html’,body=attributes.Renderer.renderLayout(layout=“email/signatureEmail”, args={rc=attributes.rc}));

sentEmail = mailService.send(sendEmail);

Enter code here…
`

I’m about to loose my mind with this one… is there something I am missing here, or are some really weird gremlins screwing with my mind???

Many Thanks to anyone that can save my sanity.

Jason

LOL, that is some weird stuff. Have you tried restarting the server, just in case.

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Very wierd… tried absolutely everything… even tried running it on another server (cf10 and 9)… I;m about to head home and see if a scotch or four can’t help bring some clarity to a bizarre situation.

I’ve narrowed it down to where I am passing the args into the addMailPart. Firstly I noticed I had a bracket in the wrong place… (thought I had cracked it), moved it into the right place, but still got error.

I then removed the args paramater, so I have this:

sendEmail.addMailPart(charset='utf-8',type='text/html',body=attributes.Renderer.renderLayout(layout="email/signatureEmail");

and it works, but then I can’t get my rc into my view or layout.

Can you try using a deep copy of the variables for prc and see how you go, I think you are experiencing a case where a thread is taking longer than the actual request.

Thanks Andrew, what do you mean by ‘deep copy of the variables for prc’?

When you pass something in to a function, or even pass into a thread will be by reference. So to break that you need to deep copy the information.

http://www.aaronwest.net/blog/index.cfm/2004/11/16/Defining-deep-copy-and-ColdFusions-Duplicate-Function

Should explain it better.