I am currently working with a client that sends large amounts of mail using ColdFusion. They are having a few problems, and I am going to be doing some optimizations to improve their mail delivery. One of the things we are going to do involves monitoring the number of messages in the ColdFusion spooler directory that are waiting to be handed off to the SMTP server. This involves looking at the files in the ColdFusion spool directory. I did not want to hard code the path to the spool directory, because it may change between production and development machines, and the path may also change when ColdFusion is upgraded.

It is possible to find the spooler directory programatically. My first thought was to look in the adminapi. No luck there. But digging around in the ColdFusion ServiceFactory java class lead me to my answer:

<cfset sFactory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset MailSpoolService = sFactory.mailSpoolService>

<cfoutput>#MailSpoolService.getSettings().spooldir#</cfoutput>

This will give you the value: {neo.rootdir}/Mail/Spool

All you need to do is replace the {neo.rootdir} part with the path to the ColdFusion installation directory. We can find that in the built-in server scope variable Server.ColdFusion.rootdir. So to put it all together:

Replace(MailSpoolService.getSettings().spooldir,"{neo.rootdir}",
      Server.ColdFusion.rootdir)

gives you: C:\CFusionMX7/Mail/Spool on Windows and /opt/coldfusionmx7/Mail/Spool on Linux.

If you are on Windows, you’ll probably want to replace those funny looking slashes:

Replace(Replace(MailSpoolService.getSettings().spooldir,"/","\\","all"),
      "{neo.rootdir}",Server.ColdFusion.rootdir)

This returns: C:\CFusionMX7\Mail\Spool

This should always point you to the spool directory on ColdFusion 6 on up to 8 and beyond, theoretically.

I have read of a few rare instances where the Server.ColdFusion.rootdir variable did not hold the correct value. I have no idea under what circumstances this occurs, but be aware there is an alternative way to get this value, which may yield better results:

sFactory.RuntimeService.getRootDir()

4 Comments

  1. mark Kruger says:

    Ryan, Nice write-up. Someday someone needs to publish a list of links for all the little “service factory” tips that are out there.

  2. Ash says:

    Excellent stuff, thanks Ryan… I had been messing around trying to find the structure by debugging CFAdmin, but this sorted my problem out straight away.

  3. hoteles says:

    Thanks for great tips

  4. Adrian Lynch says:

    I wonder what happens if you try and set it to something else?

Leave a Reply

You must be logged in to post a comment.