Reputation: 1792
I'm trying to use ColdFusion to send out emails containing attachments stored on our server.
To manage these attachments we call them 1.jpg
, 2.doc
... n.ext
where n
is a key in a database where we hold other information about the file such as its original filename.
I can use the code:
<cfmailparam file="c:\path\1.doc">
to specify the file, but it is then attached to the email as 1.doc
. Is there anyway I can override this and specify my own filename separately from the file?
Upvotes: 5
Views: 4067
Reputation: 20603
ColdFusion 2016 added this new attribute called filename to override the filename specified in the file attribute. A sample example is below
<cfmail from="[email protected]" subject="filename test" to="[email protected]" username="[email protected]" password="password" server="localhost" spoolenable="false">
<cfmailparam file="c:\Book2.xlsx" filename="Offers.xlsx">
Check out the new offers sheet
</cfmail>
Now when the mail is sent to the user he/she will see this as Offers.xslx instead of Book2.xslx. More info at https://tracker.adobe.com/#/view/CF-4019518
Upvotes: 3
Reputation: 678
Since CF8 you can use file and content as per : http://www.bennadel.com/blog/1220-coldfusion-cfmailparam-s-new-content-attribute-is-awesome.htm
<cfmailparam
file="someNiceName.doc"
content="#fileRead( yourNastyFileName.doc )#"
/>
Upvotes: 1
Reputation: 91
You can try adding:
<cfmailparam
file="#actual_file_name#"
disposition="attachment; filename=""#changed_file_name#""">
The multiple quotes are deliberate... I they allow spaces in the file name.
Upvotes: 9
Reputation: 4118
If you are running 8.0.1 (do cfdump var="#server#" to find out) then this might make your life a little easier:
From:
http://www.adobe.com/support/documentation/en/coldfusion/801/cf801releasenotes.pdf
Upvotes: 1
Reputation: 17132
Ryan's suggestion is probably the easiest solution. If you're on CF 8.01 you can make use of cfmailparam
's new remove
attribute. After you've renamed your attachments with cffile
and passed them to cfmailparam
, Coldfusion will delete them from disk for you once they have been processed by the mail spool:
<cfmailparam file="#File_path#" remove="true" />
(Before version 8.01, you had to make sure that your app didn't delete the temp files before Coldfusion's mail spool was finished with them.)
Alternatively you could call Coldfusion's underlying Java and construct your email message with attachments from memory only, with whatever names you fancy. Check out Dan Switzer's blog for an example on CF 7.02.
Upvotes: 4
Reputation: 13896
currently the only way to do this would be to use cffile and make a copy of the file in a temporary directory, rename it and then attach that. Then you would just want to delete the file once you are finished. I don't think there is a way to attach a file but call it something different when attaching to an email.
Upvotes: 1