I’ve been trying lately to convert text to a byte array for use with a Java-based mail proxy service. I need to bypass the CFMAIL tag so that I don’t have to take the performance hit of two CFFILEs to write a file to disk and then read it when creating the email. So create an attachment, I had to send the class a byte array instead of straight text.
I tried this code which worked but still took a measurable amount of time to process
<cfscript>
attachment = createObject("java", "the.attachment.class");
attachText = toByte(toBase64(origText));
attachment.setContent(attachText);</blockquote>
</cfscript>
Then I discovered Chris Cantrell’s blog where he already went through this process for one of his projects and discovered it couldn’t be more simple.
<cfscript>
attachment = createObject("java", "the.attachment.class");
attachText = origText.getBytes();
attachment.setContent(attachText);
</cfscript>
Now this saved about 80ms-210ms per transaction, which at the level this application is creating emails, is a huge savings. Of course, this is on top of a savings of approximately 500ms over the CFMAIL solution.
Leave a reply