Max Boy
Max Boy

Reputation: 327

Coldfusion, send cfhtmltopdf by email

Is possible to send a pdf created using cfhtmltopdf in the email? I'm trying to set the cfhtmltopdf in a variable and send by email, but I think it is not possible.

Here is my test cfhtmltopdf:

<cfhtmltopdf
  orientation="portrait"  pagetype="A4" margintop="1" marginbottom="1" marginleft="1">
  <html>
  <head>
  <body>
    <table>
      <tr>
        <th>Test1</th>
        <th>Test2</th>
        <th>Test3</th>
      </tr>
      <tr>
        <td>ABC</td>
        <td>ABC</td>
        <td>ABC</td>
      </tr>
      <tr>
        <td>ABC</td>
        <td>ABC</td>
        <td>ABC</td>
      </tr>
      <tr>
        <td>ABC</td>
        <td>ABC</td>
        <td>ABC</td>
      </tr>
    </table>
  </body>
  </head>
  </html>
</cfhtmltopdf>

Upvotes: 0

Views: 382

Answers (1)

rrk
rrk

Reputation: 15846

Simply add destination attribute with the path for creating the file, then use that path for the mail.

<cfset filePath = GetTempDirectory() & "emailfile.pdf">
<cfhtmltopdf destination="#filePath#" orientation="portrait"  pagetype="A4" margintop="1" marginbottom="1" marginleft="1" >
  <html>
  <head>
  </head>
  <body>
    <table>
      <tr>
        <th>Test1</th>
        <th>Test2</th>
        <th>Test3</th>
      </tr>
      <tr>
        <td>ABC</td>
        <td>ABC</td>
        <td>ABC</td>
      </tr>
    </table>
  </body>
  </html>
</cfhtmltopdf>
<cfmail to="..." .... >
    <cfmailparam file="#filePath#" disposition="attachment" type="#fileGetMimeType(filePath)#" remove="true">
    <cfmailpart type="html">Content</cfmailpart>
</cfmail>

Upvotes: 4

Related Questions