coldfusioncfmlcfmailcffile

Difference b/w remove attribute in cfmailparam and cffile action="delete"


I am using CF 2021 version. And I've created and attached an excel file to the cfmailparam tag. After delivering the email successfully, I need to delete the excel created from the server.

<cfmailparam file="#theFile#" type="application/msexcel" disposition="attachment" filename="test.xls" remove="true">

The email is sending successfully while using remove attribute. But when I use,

<cffile action="delete" file="#theFile#">

the mail is not sending out. Is this because the file deleted before the mail delivery?


Solution

  • TLDR, Yes.

    Use spoolenable="false" in the CFMail tag if you want to send it immediately and then you can delete the file after sending. By default, emails are spooled to a temporary location and the message is sent in a separate thread based on a background schedule. If you delete the file before the temp email file can be successfully processed, the ".cfmail" file will be moved to the "Undelivr" folder and never be deliverable even if you move it back to the "Spool" directory because the attachment file is missing.

    I recommend copying the file to a non-public directory path and then using remove="true" to the cfmailparam tag. You don't need to perform any additional clean-up when you use this approach.

    NOTE: Adobe introduced a bug a couple versions back where files were deleted if the remove attribute wasn't provided... this was a change from past behavior and resulted in some of our documents being deleted. As a result of repeatedly encountering bugs-beyond-our-control, we always copy the original as a new unique file and explicitly set the remove attribute.