Cfmail attachment
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=[email protected]
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">
I was able to insert the attachment into the table using your suggestion, #cffile.serverfile#.
Regarding the display of the attachment inside cfmail, it is on top instead of on the bottom after the text. Here is a snippet of the cfmail code :
<tr>
<td class="TitleText" >Shipment Number:</td><td class="TitleText" >#form.shipmentNumber#</td>
</tr>
<tr>
<td class="TitleText" >Date Submitted:</td><td class="TitleText" >#dateformat(now(), "mm/dd/yyy")# #timeformat(now(), "hh:mm:ss tt")#</td>
</tr>
<tr>
<td class="TitleText" >Type of Issue:</td><td class="TitleText" >#qryGetIssuesType.issueType#</td>
</tr>
</table>
<p align="justify">
#form.comments#
</p>
<p>
<cfmailparam file="#cffile.serverDirectory#\#cffile.serverFile#" />
</p>
</cfmail>
This should display the Shipment number, date submitted, etc, then the attachment ? The actual output has the atttachemement first, then the shipment number, date submitted, etc...
I want the attachement as the last item in the cfmail.
Similar Messages
-
CFMail Attachment Issue (410 character limit)
My company is in the process of upgrading from CF5 to CFMX7
(v7.0.2). While testing the new version our test environment, I've
discovered an issue (that didn't exist in CF5) regarding email
attachments. I've scoured the internet looking for users who might
have run into this issue and haven't found any.
Here's the problem that shows up when using CFMX7. Emails
that have attached files that have lines of code that are longer
than 410 characters per line have the lines broken apart with a
newline character.
So for example if code in a file originally looked like this,
<font face='courier new' size=-2>
 LIFE MED (line
continues out to over 600 chacters)...
</font>
The received file would have code that looked like this,
<font face='courier new' size=-2>
 LIFE MED (line
continues out to just 410 chacters, then breaks to a new line)...
bsp;  LIFE
</font>
Notice that the non-breaking space characters starting the
second line have been chopped off.
This causes an issue because the files we are attaching to
the emails are bills (formatted in html) that uses a lot of
non-breaking space ( ) characters for formatting purposes.
Most of the lines of code are greater then 410 characters wide, and
once the the characters start to get broken apart, they
end up displaying in a browser.
Things I've tried that haven't helped.
1) Changing the Default CFMail Charset from UTF-8 to US-ASCII
2) Using the cfmailparam tag instead of the mimeattach
attribute
3) Applied hot fix hf702-65414 (which was for an issue
regarding email spooling)
Does anyone know how I would prevent the line break issue in
CFMX7?
I figured I'd ask around in a few newsgroups before we
started spending money on support from Adobe.
Thanks,
Wayne BarcaIf the attached file doesn't have to be interactive, how
making it a PDF? -
CFMAIL Attached vs. embedded (cfmail, multipart/mixed)
I want to send a mail which has a PDF attachment and an embedded image. When I send them both with cfmailparam (with correct disposition) they arrive in the email as attachments in the body...you don't get the little email paperclip attachment icon.
When I tried using mimeattach for the PDF it did work!...but the image denoted with cfmailparam also came through like that. So I looked the email headers of both and the good one was Content-Type: multipart/mixed; while the bad one was "multipart/related".
So how can I make cfmailparam send it as multipart/mixed? (if that's even the right question...maybe I should stick with mimeattach and do something else?)
Thanks Folks' - RandyI never found a solution using cfmail. I had to resort to java instead.
I have all of my file information (including content) in a query called qFiles and loop through that in the code below.
<cfscript>
// config will stay this way
emailServer = serverAddressHere;
emailServerAccount = "";
emailServerPwd = "";
// set email variables
vSentFrom = sentFromEmailHere;
vSubjectText = subjectHere;
recipientsTo = listToArray( SentToListHere );
recipientsCC = listToArray( CCListHere );
recipientsBCC = listToArray( BCCListHere );
// set javamail properties
props = createObject("java", "java.util.Properties").init();
props.put("javax.mail.smtp.host", emailServer);
// get static recipient types
recipientType = createObject("java", "javax.mail.Message$RecipientType");
// create the session for the smtp server
mailSession = createObject("java", "javax.mail.Session").getInstance(props);
// create a new MIME message
mimeMsg = createObject("java", "javax.mail.internet.MimeMessage").init(mailSession);
// create the to and from e-mail addresses
addrFrom = createObject("java", "javax.mail.internet.InternetAddress").init(vSentFrom);
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsTo ); cfIdx++)
addrTo[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsTo[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.TO, addrTo[cfIdx]);
if(ArrayLen(recipientsCC)){
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsCC ); cfIdx++)
addrCC[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsCC[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.CC, addrCC[cfIdx]);
if(ArrayLen(recipientsBCC)){
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsBCC ); cfIdx++)
addrBCC[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsBCC[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.BCC, addrBCC[cfIdx]);
// build message
// set who the message is from
mimeMsg.setFrom(addrFrom);
// set the subject of the message
mimeMsg.setSubject(vSubjectText);
// create multipart message: only needed if you're including both plain/text and html
// or using attachments
multipart = createObject("java", "javax.mail.internet.MimeMultipart").init();
// specifies that the message contains both inline text and html, this is so that
// images given a cid will show up when rendered by the e-mail client
multipart.setSubType("mixed");
// create html text multipart
oHtml = createObject("java", "javax.mail.internet.MimeBodyPart").init();
// add the html content (the setText() method shortcut/only works for "plain/text")
oHtml.setContent( emailContentHTML, "text/html");
// add the body part to the message
multipart.addBodyPart(oHtml);
// loop over files to attach to the email
for ( intRow = 1 ; intRow LTE qFiles.RecordCount ; intRow = (intRow + 1))
// set file info to vars
fileContent = qFiles["fileContent"][intRow];
fileMimeType = qFiles["mimeType"][intRow];
fileName = rereplace( qFiles["filename"][intRow] , '(?!\.[^.]*$)\W' , '' , 'all' );
if(len(fileName) > 50)
{fileName = mid(fileName,1,44) & right(fileName,find('.',reverse(fileName)));}
// attach an inline binary object
att = createObject("java", "javax.mail.internet.MimeBodyPart").init();
// create an octet stream out of the binary file
os = createObject("java", "org.apache.axis.attachments.OctetStream").init(fileContent);
// we now convert the octet stream into the required data source. using an octet stream
// allows us pass in any binary data as a file attachment
osds = createObject("java", "org.apache.axis.attachments.OctetStreamDataSource").init("", os);
// initialize the data handler using the data source
dh = createObject("java", "javax.activation.DataHandler").init(osds);
// pass in the binary object to the message--javamail will handle the encoding
// based on the headers
att.setDataHandler(dh);
// define this binary object as a PDF
att.setHeader("Content-Type", fileMimeType);
// make sure the binary data gets converted to base64 for delivery
att.setHeader("Content-Transfer-Encoding", "base64");
// specify the binary object as an attachment
att.setHeader("Content-Disposition", "attachment");
// define the name of the file--this is what the filename will be in the e-mail client
att.setFileName(fileName);
// add the body part to the message
multipart.addBodyPart(att);
//end loop through qFiles
// place all the multi-part sections into the body of the message
mimeMsg.setContent(multipart);
// in this section we'll build the message into a string. you could dump
// the string to a file in most SMTP server's queue file for delivery
// this is exactly what would be pass to the SMTP server
// create a bytearray for output
outStream = createObject("java", "java.io.ByteArrayOutputStream");
// create a budder for the output stream
outStream.write(repeatString(" ", 1024).getBytes());
// save the contents of the message to the output stream
mimeMsg.writeTo(outStream);
// save the contents of the message to the sMailMsg variable
sMailMsg = outStream.toString();
// reset the output stream (for stability)
outStream.reset();
// close the output stream
outStream.close();
// create a transport to actually send the message via SMTP
transport = mailSession.getTransport("smtp");
// connect to the SMTP server using the parameters supplied; use
// a blank username and password if authentication is not needed
transport.connect(emailServer, emailServerAccount, emailServerPwd);
// send the message to all recipients
transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
// close the transport
transport.close();
</cfscript> -
Cfmail: attach file with cfmailparam?
Greetings
I created a form several years ago that allows users to submit maintenance requests. They check a box if they want a receipt sent to their own email.
The requests do not get captured in a DB- simply sends to email.
This all has been working fine- I am now attemping to add document attachment capability- I am obviously not using the correct method.
The form itself has:
<cfform action="request_action.cfm" method="post" name="detail" id="detail" enctype="multipart/form-data">
etc. etc.
Upload File or Sceenshot if neccessary: <cfinput name="file_upload" type="File" required="no" size="40"></cfform>
The request_action.cfm has:
<cfmail to=
etc. etc.
<cfif isDefined("Form.file_upload") >
<cfmailparam
contentID = "file_upload"
disposition = "attachment"
file = "#Form.file_upload#"
type ="application/msword,application/docx,application/pdf,application/octet-stream,applicatio n/msword,text/plain,binary/octet-stream, image/pjpeg, image/gif, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-word.document.12, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"></cfif>
</cfmail>
When I run without the above code, everything works. When I run with the cfmailparam, it sends a strange receipt with no content?
Thanks for any help with this
NormanYou didn't post any code that shows that you actually uploaded the file to your server.
-
I want to dynamically attach a document and send via cfmail.I
use various queries to get the recipent names, and unique id info,
then retrieve the document that corresponds.
One cfmail documentation says to use cfparam inside cfmail
and specifiy the full path. Another says to use the mimeattach
attribute with the full path.
This is where I am having the problem. My document
name/variable from my query is #qryName.document#.
How do I set this up with the path, in either cfparam or
mimeattach ?I understand your code, but I still cannot seem to get the
correct path.
I use this query to find th file that I want as an
attachement to the cfmail :
<cfquery name="qryName" datasource="dbname">
select
uploadFileName
from tableName
where docNo = '#form.DocNo#'
</cfquery>
So the file that was uploaded with this docNo is stored in a
variable named uploadFileName in the specifield table.
What is the full path that I would setup in cfmailparam so
that this documant is an attachemetn in cfmail ? -
Attaching generated excel file in cfmail
Hi,
I've attached the code in which I've generated an excel file
from my data, which the user can then open/save on their PC. I now
want to attach this excel file to an email (using cfmail) and send
it (the task will then become scheduled).
How do I save rather than output the excel file?
KatieHi,
Have a look at the following tags:
1)
<cfsavecontent> to generate a variable from your
tab-delimited content
<cffile action = "write"> to generate a temp file with
your content
<cfmail> and attach that file to your email
or
2)
<cfsavecontent>
<cfmail>,<cfmailpart> to attach the variable
directly to the email without creating a temp file first (have not
tried that myself)
cheers,
fober -
I have a function which creates some xls-files and pack it
into a zip-archive, the created file is named 1234.zip and is saved
at the server. This function works correct.
After that the created file should be send by cfmail but when
I receive the mail the attached file is named
att23423.att or similar. The file itself is correct, I can
open it with winZip but I also need the correct filename for the
attachment.
I run the same function for sending xls- or pdf-files and
this works!
Any Ideas?? I would appreciate any suggestion.
I use CF MX7.02 and here is a snippet of the relevant code:
<cfmail to="#sender#" bcc="#receiver#" from="#sender#"
subject="#subject#" server="#application.smtp_server#"
port="#application.smtp_serverport#" type="HTML">
...<cfmailparam file="#attach_file_name#"
type="application/zip">...
</cfmail>Hi Guido,
There is not a very complex configuration required for attachments. You have to follow the general configuration steps along with the instructions mentioned at below link -
http://www.b2bgurus.com/2008/11/attachment-feature-in-ebms-using-oracle.html
Regards,
Anuj -
I set up a form that emails the form results to an email
address. It also has an option to attach a file.
My problem is that when the email is received the attachment
has been turned into a .tmp file. How can I get it to keep its
original file extension so that the receiver doesn't have to guess
the file type in order to open it.
<cfmail to="[email protected]" from="#FORM.email#"
subject="Web Site Email" mimeattach="#FORM.uploadfile#">
</cfmail>
Any help is greatly appreciated.OK if you use a file upload form then the file is uploaded by
the web server to to a temporary location, this is why the filename
you have is a .tmp file. If on the action page for the file upload
you use <cffile action="upload" .../> then you can give the
file the correct name and extension.
the next thing you need to understand is that when you send
an email with cfmail, all you are doing is putting an email in the
queue for your email server. So when you attach a file to an email
you must make sure that the file is still there when the mail
server tries to send the email as that is the point where it
attaches the file.
It will stay on your server until you do something about it,
if this is not the intended functionality then you could use
cfschedule to remove all files in a folder older than a few hours
or even a day to be on the safe side.
In answer to your question about is it accessible to other
people? Well if it is in your web root and someone can guess the
URL then yes, but these files do not need to be saved in the
webroot if they are only to be emailed, so you can protect them by
saving them elsewhere. Hope that helps! -
Cfmail/cfmailparam attachment encoding
When a text file is attached to an email, cfmail attempts to determin the mime type of the file and encodes it. This alters the content of the file somewhat. As best I can tell it is at least inserting line breaks.
Is there a way to attach files that are not encoded or altered in any way?
Thanks for any help.This will happen at the recipient's end depending on the mail
server/client they use ... you could send a pdf from your desktop
to the same recipient and it will happen with that too.
It could be a security reflex that it changes the file to a
non-binary format if it is not trusted or seems to be coming from a
questionable source.
A number of the government servers seem to do that - no idea
why, but renaming the file at the recipient's end generally allows
it to open properly.
Nothing you do in your code is going to change that.
*** If you are storing the file on the server, you may want
to include a line in the message that gives them a URL if the
attachment can not be viewed properly. -
I'm using a simple form to email a text file that I've used
before with no problems but for some reason it's not going through.
Either the email goes through without the attachment or doesn't go
through at all. Should I be be using cfmailparam instead?Yes you should use the cfmailparam tag to send the file
<CFMAILPARAM FILE="#form.file#">
It looks as though you may need to upload the file first
before sending.
<cffile action="upload"
destination="c:\attachmentsfolder\" nameconflict="MAKEUNIQUE"
fileField="form.file">
then you'd use the mailparam like so:
<CFMAILPARAM
FILE="c:\attachmentsfolder\#cffile.ServerFileName#.#cffile.ServerFileExt#">
the cffile. scope will be available after the <cffile
action="upload" takes place -
I'm trying to send the email from my AOL account... it works
fine hosted locally... and doesnt when I upload it to my GoDaddy
hosted account... Is there some GoDaddy setting I need to use... or
if I have to use a GoDaddy created email address... what settings
do I use... I'm not much of a programmer... so please explain like
ur talking to a 2-year old.
<---THE CODE IS BELOW --->
<CFMAIL FROM="[email protected]"
TO="[email protected]" SUBJECT="Survey Request Submitted !"
server="smtp.aol.com" username="harryleroybrown" password="doctor"
PORT="587">
There has been a form submission on your site, here's what
they had to say:
Sender name: #form.requesting_company#
Sender email: #form.Requestor_Email_Address#
Address (1st location only):
#form.location1_address_street#,
#form.location1_address_city#,#form.location1_address_state#
Message Sent: #DateFormat(now(), 'mmmm dd, yyyy')#
#TimeFormat(Now(), 'hh:mm:ss tt')#
</CFMAIL>Highly unlikely you are going to be able to do exactly what
you want to do.
1) AOL will probably disallow a connection remotely like this
2) GoDaddy might not allow a connection out like this
3) GoDaddy will probably not allow you to send an email out
from their servers with an AOL address
Good idea regarding removing the username, password, server
and port. Hopefully you have a godaddy email account attached to
your hosting that you can try first. Then try to get more
complicated. -
Attach page content as pdf in email
Thanks for all who answer this thread.
I am using this syntax to send email from a web page....
<cfset subject = "Application Name">
<a
href="mailto:?subject=#urlEncodedFormat(e_subject)#">Email
page</a>
i know, how to create page content in pdf...
How can i attach page content pdf to this mail? is that
possible?.
OR
what is best way to send page content PDF as email.....
user want to type some info in body of email.....
thanksUse cfsavecontent to generate your page content.
Use cfdocument to create the pdf file
Use cfmail and cfmailparam to send it as an email
attachment. -
Email with attachment in CF8.0.1
Hello,
We have some ebiz applications which sent out emails with a
file attachment. After we upgraded ColdFusion from MX version to 8,
then 8.0.1, the emails cannot be delivered with an attachment.
The ColdFusion Mail Spool Encountered An Invalid Spool File
In The Spool Directory. The invalid file MailXXXXXX.cfmail was
moved to the undeliverable directory.
Any suggestions? Thank you for the help.Thank you Azadi, the link is very much appreciated.
I wonder why it hasn't yet shown up on the official list of
CF hotfixes (
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402604&sliceId=1)
or in the CF Support RSS feed yet.
I'll post linkage to it from the two blog threads I know
about talking about this. -
Cfmail attachments not working
So I have a web page that...
1 Generates an excel file.
2 Saves the excel file to my webserver.
3 Sends an email with the excel file attached.
If the user opens the email via desktop outlook the attached
excel file will open and display just fine. If the user opens the
email via web outlook the attachment won't open. I have no idea if
this is a coldfusion problem our an outlook problem. Does anyone
have any idea's what would cause this to happen?
ThanksIt opens fine when I double click it on the server. The
correct tag is
<cfsavecontent variable="mypage">
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="
http://www.w3.org/TR/REC-html40">;
<head>
<meta http-equiv=Content-Type
content="application/vnd.ms-excel; charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 9">
<link rel=File-List
href="./headcountest_files/filelist.xml">
<link rel=Edit-Time-Data
href="./headcountest_files/editdata.mso">
<link rel=OLE-Object-Data
href="./headcountest_files/oledata.mso">
Then my table that is getting output
</cfsavecontent>
<cfset mypath =
"C:\mypath\Excel\itinerary_#uname#.xls">
<cffile action="write" file="#mypath#"
destination="C:\mypath\Excel" output="#mypage#">
This creates the excel file and saves it to my webserver.
I then do my <cfmail> and attach the file that I just
created. The metatags tell it to create the excel file. -
Cfmail - nesting error message
Greetings -
Perhaps someone can shed some light on why the following is
occurring.
I have a processing page processing form input for a event
registration.
The process works fine, displays as intended on a web page.
However,
when i enclose the code inside a <cfmail> tag I get the
following error.
==ERROR========================
Invalid tag nesting configuration.
A query driven CFOUTPUT tag is nested inside a CFOUTPUT tag
that
also has a QUERY= attribute. This is not allowed. Nesting
these tags
implies that you want to use grouped processing. However,
only the
top-level tag can specify the query that drives the
processing.
==ERROR========================
I know what the error means and all that, but I cannot see
where I
have a nesting situation occurring. I have attached the code
for
review and ensight to what I am missing here.Thanks CJ -
Talk about a forehead slapper and a DUH --
Instead of the <cfoutput> on the last table structure,
I should of
used <cfloop> with a query attribute to accomplish what
I needed.
Don't even know why I had the first set of <cfoutput>
tags. Guess
I was staring to long at it and not enough java - lol.
Thanks again for the wake up call.
Leonard B
Maybe you are looking for
-
Why JPEG - TIFF files in Bridge won´t open directly in Photoshop CC 2014?
Since a couple of weeks ago, whenever I click a jpeg or tiff file in Bridge (last reinstalled in 17/08/14) it won't open directly in Photoshop CC 2014, but in Windows photo viewer. Am I doing something wrong or is it Bridge's fault?
-
Why is tableView titleForFooterInSection is called so many times?
Hi, I have a table and I am noticing that for every new row which shows up during scrolling operation (one call to tableView cellForRowAtIndexPath there are 27 (!!!) calls to tableView titleForFooterInSection Why so many? While application seems to w
-
Patch set 11.1.0.7 applied but repository does get upgrades
Hi, My database version is 11.1.0.6 i applied recent patch set which is 11.1.0.7 and upgraded the database using database upgrade assistant. everything went successfully. but when i login the owb designer says your repository version is 11.1.0.1 when
-
Can Lion be downloaded for multiple computers (my laptop & desktop)
I need to Download Lion so I can switch my mobile me to iCloud, but I want to know if I can download it once and transfer it to all computers or do I have to pay the $29.99 for each computer.
-
Why are Illustrator measurements often not precise?
One thing that constantly frustrates me is that Illustrator invariably doesn't allow me to create precise measurements. For example, if I create a new document with an A4 page then draw an A4 box, the new box is not 210 x 297 as it should be but 210.