Skip to main content
Inspiring
May 24, 2010
Question

cfmail attachment

  • May 24, 2010
  • 1 reply
  • 2995 views

I am trying to include an attachemnt in cfmail, for  the first time.

Reviewing some of the online documentation and techniques, I found this easy one - I could not get it to work using variables so I hardcoded and it works.

<cfmail to=user1@email.com
  from="#form.customerEmail#"
  subject="Garage Sale
  mimeattach="E:\wwwroot\folder1\forms\uploadFolderName\fileName.gif"
  type="html">

A couple of questions :

The email has a body of text and it adds the atttachment before the text. What do I have to do to get the attachement after the text ?

Also, my form contains this : <td>Attachment: </td><td><input type="file" name="attachmentFile"></td>

Instead of hardcoding, how do I get the variable in there ? I tried to use the code below but it kept blowing up in the destination part (what I have in there now, I was just trying different things)

<cffile action="upload"
        filefield="attachmentFile"
  destination="#uploadFile##attachmentfile#"
  nameconflict="makeunique">

This topic has been closed for replies.

1 reply

Inspiring
May 25, 2010

cffile action="upload"

  destination="#uploadFile##attachmentfile#"

Destination is usually an absolute file path. See the simple example at the bottom of the documentation:

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_f_10.html

Once you have successfully uploaded the file the CFFILE structure (or result structure) will be populated with various keys which can be used to reference the file path (like CFFILE.serverFile and CFFILE.serverDirectory etcetera). For a complete listing, see the page above.

trojnfnAuthor
Inspiring
May 25, 2010

so I have this for the cffile upload :

<cfif isDefined("form.attachmentFile")>
<cfset uploadFolder = ExpandPath("./uploadFolder/")>
<!--- Upload the file(s) to a temporary folder --->
<cffile action="upload"
        filefield="attachmentFile"
  destination="#uploadFolder#"
  nameconflict="makeunique">

When I check the temp folder uploadFolder, the uploaded file (gif) is in there.

Do I need to use the cfdirectory ?

<cfset library_directory = "#uploadFolder#">
<cfdirectory action="list"
             directory="#library_directory#"
    name="qryGet_Files"
    filter="*.*"
    sort="datelastmodified">

Inside the cfmail, I have <cfmailparam file = "#library_directory##qryGet_Files.name#" type="image/gif"> as my attachemnt. This seems to work because when I open the mail, it  has the icon attachemtent, then the text. But the problem is that it is giving me the same uploaded file name, not a different one, which is what I select each time I test. It is always givnig me the same one file name.

Inspiring
May 26, 2010

#qryGet_Files.name# will always return the first row because you didn't specify a row number.