1

我正在制作一个创建自定义 PDF 的应用程序,将其邮寄,然后将其删除。我已经分别测试了所有 3 个组件并且它们可以工作,但是当我将它们放在一起时,电子邮件不会发送。

是否有可能在发送电子邮件之前删除附件,即使删除位于脚本中的附件之后?

这是我的代码。

<!---Get the PDF--->
<cfscript>
    PDFBuilder = createobject("component", "form_admin.email.PDFBuilder" ); 
    pdf = PDFBuilder.createPDF(form_id);
</cfscript>

<!---Create link to the pdf --->
<cfscript>
    foo =  expandPath('../email/tmp/')  & pdf & '.pdf';
</cfscript>

<!---Create email--->
<cfmail to="will@hazardousfrog.com"
        from="will@hazardoufrog.com"
        subject="Jag intrest form. "
        type="text/html" >
    <cfmailparam file="#foo#">

    Dear #getEmail.title#, #getEmail.first_name# #getEmail.surname# <br />
    Attached is a PDF boucher telling you more information about the cars you were interested in.  <br />
    Best wishes <br />
    Jaguar <br /><br /><br /><br /><br /><br /><br /><br />
    This is not actually jaguar this is a test application by Hazardousfrog.
</cfmail>

<!---Delete the file after it has been sent ---> 
<cfif FileExists(#foo#)> 
    <cffile action="delete"
            file="#foo#">
<cfelse>
    <cfoutput >
        error
    </cfoutput>
    <cfabort>
</cfif>

抱歉,如果代码不是很好,我只做了 2 周的 CF。

4

3 回答 3

4

好的,我设法从一个工作朋友那里得到了答案。

当 cfmail 被处理时,邮件被保存到一个假脱机并在大约 3 分钟后定期发送出去。就我而言,这意味着在发送邮件之前删除了电子邮件 PDF 附件,因此邮件无法发送。

ColdFusion 邮件标签有一个属性,可以立即发送或保持假脱机状态。

spoolenable :是假脱机邮件还是总是立即发送。

因此,为了让我的代码正常工作,我将此行添加到我的邮件属性中。

spoolenable="false"
于 2012-08-30T09:54:51.447 回答
4

另一种选择是使用 cfmailparam 标签的 remove 属性,它会告诉 CF 在文件发送后删除文件。这样,您的 spoolenable 属性可以为真,它应该可以按需要工作。版本 8.0.1 中引入了 remove 属性。

于 2012-08-30T11:06:22.290 回答
1

我还会fileExists()在 cfmail 代码周围放置一个关于 pdf 文件是否确实已创建的内容。

于 2012-08-30T09:59:36.183 回答