4

So, yet another weird issue with ColdFusion (9 I believe I'm using).

When I send an email, my attachment is being deleted from the directory!!

<cfmail to="#to#" from="#from#" subject="#subject#">
<email content here>
<cfmailparam disposition="attachment" file="imagename.jpg">
</cfmail> <!--- email details omitted because irrelevant --->

When I run that, the attachment sends, but it deletes it from the folder it was stored in (same directory as the script).

However, when I change the file path to the FULL path, it works fine.

file="C:\yadda\yadda\yadda\scripts\imagename.jpg"

Why does the first option send the attachment but remove it from the folder?

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
  • I have not tested it, but according to [the docs](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c15.html) the default behavior should be `remove="no"`. Any change if you explicitly set it to "no/false"? – Leigh Nov 22 '13 at 20:53
  • No change, it's still deleting them – Sterling Archer Nov 22 '13 at 21:01
  • What happens when you try *both* true/false with the full path? ie Does it respect the settings? If yes, obviously change your code to use that. Truthfully, I always use full paths anyway to avoid ambiguity. With regards to the original problem with file name only, does it happen consistently? If so, put together a repro case and file a bug report. If it *is* a bug, that is probably the best you can do. – Leigh Nov 22 '13 at 21:34
  • I used the full path regardless, as it didn't delete my attachment from the folder. I was just wondering why a non-full path would delete it (and now, wondering why it does when remove="no"/"false" – Sterling Archer Nov 22 '13 at 21:40
  • 2
    Right, but I am curious if it respects the setting *at all*. That is why I suggested testing both remove=true/false using a full file path (to get a better idea of the scope of the problem). That said, I do not know why it would delete the files - other than it being a bug in the behavior. So putting together a solid repro would help prove/disprove that theory. IF it is a bug, there is probably not much else you can do beyond filing a report. (BTW, I cannot test it now, but will try it out later). – Leigh Nov 22 '13 at 21:55
  • I cannot duplicate your results with 9,0,1,274733. When only a file name is used, CF *never* deleted the file. Even when I specified `remove="yes"`. When using a full path, it worked as advertised: `remove="no"` or omitting the `remove` attribute preserves the file. Using `remove="yes"` deletes the file. Sounds like there is something else going on .. – Leigh Nov 23 '13 at 17:27
  • Aside from the content of the email (raw text), that was the ONLY thing the script was used for. That's why I'm so puzzled because even with `remove="no"` it did not respect the file – Sterling Archer Nov 23 '13 at 22:35
  • Well, like said I have only [tested the scenario](http://pastebin.com/rbq38Yir) with 9,0,1,274733 and windows 7, but could not reproduce your results. The only case in which the file *was* deleted was case 6: full path and `remove="yes"`. (What version and o/s are you using BTW?) That said, the comment by tibc-dev suggests he *has* seen that behavior, and the solution was what you discovered already: use a full path. Beyond putting together a test case and submitting a bug report, there is not much else you can do. – Leigh Nov 24 '13 at 17:15
  • Oh yes, I will always use a full path now -- my co-worker told me that. I just was curious as to why a non-full path would do that (I was using Mac OSX Mavericks with CF9 I believe) – Sterling Archer Nov 24 '13 at 21:44

1 Answers1

1

ColdFusion requires you specify the correct file path to the attachment. This quirk/bug has existed for a while and believe still exists in CF10. Through trial-and-error (due to incomplete documentation) have learned that all relative paths will be deleted irregardless of remove="false" in addition should you use a virtual directory, you will encounter the same result with the file being deleted.

So in your example, you would need to use:

<cfmailparam disposition="attachment" 
             file="C:\yadda\yadda\yadda\scripts\imagename.jpg" />  or
<cfmailparam disposition="attachment" 
             file="/{unix path}/{to}/{my attachment}/imagename.jpg" />
tibc-dev
  • 973
  • 11
  • 16
  • Odd. Out of curiosity, which o/s's did you observe this behavior? I [tested with non-virtual paths under CF 9,0,1,274733 and windows](http://pastebin.com/rbq38Yir) and CF **never** deleted the file when relative paths were used. Though like I mentioned earlier, I think it makes more sense to use a full path anyway. – Leigh Nov 24 '13 at 14:21