• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFDOCUMENT & EMAIL

Contributor ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Hello,
I created a script that builds a purchase order with the items in the database.
In order to have it in PDF, I surrounded it with a CFDOCUMENT:
<CFDOCUMENT format = "pdf" filename = "Bon_commande_ # IC_ID # .pdf">
I would like to send this document by email:
<cfmailparam file = "http: //site/Admin/_ebooks/Commande_bon.cfm? IC_ID = # IC_ID #" content = "Bon_commande_ # IC_ID # .pdf">
But I have no results 😉
Thank you in advance for your help

Views

475

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Hello, ZNB,

 

I believe the file you want to send must be the local hard drive path, not a URL.  By this, I mean the file should be saved to the server hard drive, and the path to that file is what you put in cfmailparam.

 

HTH,

 

^ _ ^

 

UPDATE:  Please see this - https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmailparam.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

You have a couple of choices.

 

First, expanding on Wolf's point: yep, if you're using the FILE attribute of cfmailparam, you don't specify a URL but a filename.

 

And note that if you don't specify an absolute path (for either that cfmailparam FILE or the cfdocument FILENAME attributes), they both presume to look for the named file in the current folder where the template is run. As such, you COULD just use this to fix your problem:

 

<cfmailparam file = "Bon_commande_#IC_ID#.pdf">

 

Note that I don't show using the content attribute like you have. You don't need it.

 

In fact, its purpose is so that you can name a variable holding the contents to be used for the file to be attached, rather than naming a file on disk. And that's a second way you could go, if you have no real need to create and save the file in the CFDOCUMENT.

 

You could switch it from using cfdocument's FILENAME attribute (which saves to a file) to using instead NAME (which names a variable--similar to the cfquery NAME attribute). And that could name any variable (the docs say it has to exist first--it does not). Then you would change the cfmailparam to name that variable in that CONTENT attribute. Note that you STILL have to use a FILE attribute for cfmailparam, in order to give a name to the file as it will be created in the attachment. Here's an example:

 

 

 

<cfdocument format="pdf" name="pdfoutput" overwrite="yes">
test
</cfdocument>

<cfmail to="whoever" from="whoever" subject="test cfdocument mail">
<cfmailparam file="somename.pdf" content="#pdfoutput#">
</cfmail>

 

 

 

Either way, let us know how things go. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

Charlie,

 

As usual, I learn a lot of stuff whenever I read your responses.  However, according to Adobe documentation for CFDOCUMENT, it's not FILE that is used to name a variable to store the PDF in.  It's NAME (almost halfway down the page.)  If the documentation is incorrect, Adobe should be notified.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

Yep, you're rught. That was a copy/paste error (early in writing that note). And I see now that I had provided a code example, that in fact SHOWED using NAME, so it was just a finger flub in my discussion.  I'll have corrected that in the original comment, for future readers. (And they can see our last two notes explaining why I am correcting things.)

 

 

 

Thanks!


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

ZNB, did you ever resolve things? Did any of our comments help?


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Use

 

<cfset Bon_commande_pdf=expandPath('Bon_commande_#IC_ID#.pdf')>
<CFDOCUMENT format = "pdf" filename = "#Bon_commande_pdf#">


<cfmailparam file = "#Bon_commande_pdf#" type="application/pdf">

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Other possibilities, depending on the use-case:

<!--- Same user, email sent later in the same request--->
<cfset request.Bon_commande_pdf=expandPath('Bon_commande_#IC_ID#.pdf')>
<CFDOCUMENT format = "pdf" filename = "#request.Bon_commande_pdf#">


<cfmailparam file = "#request.Bon_commande_pdf#" type="application/pdf">
<!--- Same user, email sent later in the same session--->
<cfset session.Bon_commande_pdf=expandPath('Bon_commande_#IC_ID#.pdf')>
<CFDOCUMENT format = "pdf" filename = "#session.Bon_commande_pdf#">


<cfmailparam file = "#session.Bon_commande_pdf#" type="application/pdf">

 

<!--- Email sent by any user at any time later during the application--->
<cfset application.Bon_commande_pdf=expandPath('Bon_commande_#IC_ID#.pdf')>
<CFDOCUMENT format = "pdf" filename = "#application.Bon_commande_pdf#">


<cfmailparam file = "#application.Bon_commande_pdf#" type="application/pdf">

 

 

 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

LATEST

@ZNB,

Do you now have the desired result? Please give some feedback to the forum. It will help others who encounter a similar problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation