CFMail listener is never called

cfmail listener with async="true": mail is sent in the calling thread, never retried, and the listener is never called

Prepared 2026-11-27 by Andrew Penhorwood (ColdBits, LLC) with AI Claude.

Summary

With the mail extension, giving <cfmail> a listener together with async="true" breaks three documented behaviours at once:

  1. The mail is not queued. The spooler cannot save the task, so it sends the mail in the thread that ran cfmail. The request waits for the SMTP conversation (30 seconds when the mail server does not answer).
  2. There are no retries. Because the task was never saved, a failed try is the only try.
  3. The listener’s after is never called, whether the try passed or failed.

The same cfmail with no listener is queued and retried as documented.

Environment

Lucee 7.1.2.189-RC (lucee-zero-7.1.2.189-RC.jar)
Mail extension org.lucee:mail 1.1.0.24 (deployed 2026-11-02). Versions 1.1.0.6 and 1.1.0.17 have the same class shapes (see Analysis)
Java OpenJDK 25.0.4
Servlet container Jetty 12.1.12
OS Windows 11 Pro (development PC). Two Linux servers run the same Lucee version; the behaviour was observed on the Windows PC only
Config mailSpoolEnable: true, mailSpoolInterval: 5, mailConnectionTimeout: 30

What the documentation says

  • cfmail attribute listener (<cfmail> :: Lucee Documentation): the listener can have before and after functions “that get triggered before and after sending the mail”; it “is only used when async (spoolEnable) is set to true”; it can be a component or a struct of functions.
  • cfmail attribute async: “if set to true, the mail is sent asynchronously by the Lucee Task manager (with multiple tries)”.
  • Recipe “Mail Listeners” (https://docs.lucee.org/recipes/mail-listener.md, since 6.0) shows both the per-tag form and this.mail.listener in Application.cfc.

What happens

1. The task cannot be saved, so the mail is sent in the calling thread

remoteclient.log, one line per cfmail that has a listener:

"ERROR","qtp93314457-32418","11/27/2026","14:54:43","...","remote-client","unable to persist spooler task [00001369] of type [mail]: java.util.Base64$Decoder"
"ERROR","qtp93314457-32025","11/27/2026","14:58:41","...","remote-client","unable to persist spooler task [00001370] of type [mail]: org.lucee.extension.mail.spooler.ComponentSpoolerTaskListener"
"ERROR","cfthread-2130","11/27/2026","15:08:22","...","remote-client","unable to persist spooler task [00001373] of type [mail]: org.lucee.extension.mail.spooler.ComponentSpoolerTaskListener"

  • The first line is from a listener that was a struct of closures (the closure had captured an object graph holding a java.util.Base64$Decoder).
  • The other two are from a listener that is a plain component holding only strings and numbers. Here the class that cannot be serialized is Lucee’s own ComponentSpoolerTaskListener, so no listener of any kind can be saved.

A thread dump taken while such a request was waiting shows the request thread itself doing the send, called straight from SpoolerEngineImpl.add:

"qtp93314457-32418" ... in Object.wait()
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	at java.lang.Thread.join(Thread.java:1881)
	- locked <0x000000009880d100> (a org.lucee.extension.mail.smtp.SMTPSender)
	at org.lucee.extension.mail.smtp.SMTPClient._send(SMTPClient.java:995)
	at org.lucee.extension.mail.spooler.MailSpoolerTask.doExecute(MailSpoolerTask.java:138)
	at org.lucee.extension.mail.spooler.SpoolerTaskSupport.execute(SpoolerTaskSupport.java:107)
	at lucee.runtime.spooler.SpoolerEngineImpl.execute(SpoolerEngineImpl.java:706)
	at lucee.runtime.spooler.SpoolerEngineImpl.add(SpoolerEngineImpl.java:157)
	at org.lucee.extension.mail.ReflectionUtil.add(ReflectionUtil.java:80)
	at org.lucee.extension.mail.smtp.SMTPClient.send(SMTPClient.java:864)
	at org.lucee.extension.mail.tag.Mail.doEndTag(Mail.java:680)
	at boaz.services.email_cfc$cf.udfCall1(/boaz/services/email.cfc:224)

Measured on the request: with the SMTP port unreachable, the request that ran cfmail took 30.06 seconds (three runs: 30.07, 30.06, 30.06). mail.log then shows timeout occurred after 30 seconds while sending mail message.

2. No retries

No task file for these mails appears in lucee-server/context/remote-client/open, and no later try is logged for them. Mails sent without a listener do get task files there and are retried.

3. after is never called

The listener’s after updates a database row. That row was never updated:

  • after a try that failed (30 second timeout), and
  • after a try that went through (same mail, a reachable SMTP port: the send finished at once with no error in mail.log).

cfmail itself did not throw in either case.

Analysis

Read from the compiled classes with javap (Lucee core inside lucee-zero-7.1.2.189-RC.jar, and mail-1.1.0.24.jar).

Why the task cannot be saved

  • lucee.runtime.spooler.SpoolerEngineImpl.store writes the task with java.io.ObjectOutputStream.writeObject.
  • org.lucee.extension.mail.spooler.MailSpoolerTask has a non-transient field private CFMLSpoolerTaskListener listener.
  • org.lucee.extension.mail.spooler.CFMLSpoolerTaskListener (and its subclasses ComponentSpoolerTaskListener and UDFSpoolerTaskListener) does not implement java.io.Serializable.
  • The core’s own class, lucee.runtime.spooler.SpoolerTaskListener, does implement Serializable. The extension’s listener classes are separate copies that do not extend it.

Why the mail is then sent in the calling thread

SpoolerEngineImpl.add(ConfigWeb, SpoolerTask):

if( store( config, task ) ) start( config );      // saved: the spooler thread takes it
else                        execute( config, task );   // not saved: run it here, now

Why after is never called

  • The core calls a listener only in SpoolerEngineImpl.log, and only when the task is a lucee.runtime.spooler.SpoolerTaskPro, through getListener().
  • The extension’s SpoolerTaskSupport implements lucee.runtime.spooler.SpoolerTask only, not SpoolerTaskPro, and exposes its listener as getSpoolerTaskListener().
  • No class in the mail extension calls CFMLSpoolerTaskListener.listen or getSpoolerTaskListener().

So the listener is attached to the task (SMTPClient.setListener) but nothing ever invokes it.

Minimal test case

Not run standalone: the site this was found on routes every request through one Application.cfc, so the cases above were observed inside the application. The code below is the same call reduced to its parts.

MailListener.cfc

component {
	function before( lastExecution, nextExecution, created, id, type, detail, tries, remainingTries, closed, caller, advanced ){
		fileAppend( getTempDirectory() & "mail-listener.log", "#now()# before#chr(10)#" );
	}

	function after( lastExecution, nextExecution, created, id, type, detail, tries, remainingTries, closed, caller, advanced, passed, exception ){
		fileAppend( getTempDirectory() & "mail-listener.log", "#now()# after passed=#arguments.passed ?: 'null'##chr(10)#" );
	}
}

repro.cfm (the SMTP server is a local port nothing listens on, so every try fails)

<cfscript>
param name="url.case" default="none";

mail = {
	  from: "repro@example.com"
	, to: "repro@example.com"
	, subject: "listener repro #url.case#"
	, server: "127.0.0.1"
	, port: 2526
	, async: true
};

if( url.case == "component" ){
	mail.listener = new MailListener();
}

start = getTickCount();
cfmail( attributeCollection = mail ){ writeOutput( "body" ); }
writeOutput( "case=#url.case# ms=#getTickCount() - start#" );
</cfscript>

?case=none ?case=component
Expected returns at once; task file in remote-client/open; retried the same, plus after called after each try
Seen in the application as expected the try runs inside the request; unable to persist spooler task ... ComponentSpoolerTaskListener in remoteclient.log; no task file; no retry; after never called

Suggested fix

  1. Make the extension’s listener classes serializable (or have them extend the core’s lucee.runtime.spooler.SpoolerTaskListener), so a task with a listener can be saved and retried.
  2. Have the extension’s mail task implement lucee.runtime.spooler.SpoolerTaskPro and return its listener from getListener(), or call the listener from the extension, so before and after run.
  3. When a task cannot be saved, consider throwing or logging at a level that reaches the caller. Sending the mail in the calling thread turns an async="true" call into a blocking one without any sign of it in the page.

Workaround in use

Run the cfmail inside a thread so the request does not wait. This does not bring back retries or the listener.