I have a method (see below) which will send out a bunch of emails. This all works fine, but I have been trying to get it working in a seperate thread (there could be a lot of emails), but have been having a lot of problems. I have narrowed it down to no being able to add to access the RequestContext inside the thread.
The email layout and view of the email generated inside the thread can access the items that were added to RC outside (above) the thread, but cannot access anything that I try to add to RC inside the thread.
More specifically. inside my layout (email/signatureEmail_thread), I can access rc,renewals, rc.emailView and rc.signature, which are created before the thead starts, but I cannot access rc.renewal, which is created inside the thread.
I have tried just about everything I can think of and too great to list. But the latest being to manually pass ‘event’ into the thread, but still not working.
Any pointers on how I can add the ‘renewal’ to the rc inside the threat greatly appreciated.
Jason
`
//send renewal notifications
public function emailpending(){
rc.renewals = memberService.getRenewalsPending(rc.periodID);
rc.emailView=‘membership/renewals/emails/pending_renewals’;
rc.signature = orm.get(“EmailSignature”,rc.signature);
thread name=“sendRenewals” event="#event#" renewals="#rc.renewals#" signature="#rc.signature#"{
//createObject( “java”, “coldfusion.tagext.lang.SettingTag” ).setRequestTimeout(javaCast( “double”, 1800 ));
var mailService = getPlugin(“MailService”);
rc = event.getCollection();
for (i=1; i<=arrayLen(renewals); i++){
rc.renewal = renewals[i];
try {
var email = mailService.newMail(
to = Application.settings.testemail,
from = signature.getEmailAddress(),
subject=“Membership Renewal”,
type = “html”
);
email.addMailPart(charset=‘utf-8’,type=‘text/plain’,body=renderLayout(“email/signatureEmail_thread”));
email.addMailPart(charset=‘utf-8’,type=‘text/html’,body=renderLayout(“email/signatureEmail_thread”));
sentEmail = mailService.send(email);
catch(any e) {
//log error
}
}
}
flash.put(‘success’,‘Emails have been sent to Members Pending Renewal’);
setNextEvent(url=’/index.cfm/admin/membership.renewals/listpending/#rc.periodID#’);
}
`