如何将文件附加到来自 URL 的电子邮件?

发布于 2024-11-19 05:26:26 字数 701 浏览 3 评论 0原文

我正在使用 cfmail 标签发送电子邮件,并尝试从 URL 附加 PDF 文件:

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
   <cfmailparam file="http://myfilelocation/pdfFile.pdf">
   Body of the email
</cfmail>

但是,这不起作用。如果没有 cfmailparam 标签,电子邮件发送成功。如果我访问 http://myfilelocation/pdffile.pdf,我会看到我尝试附加的 PDF 文档。我做错了什么吗?如何通过 URL 将 PDF 文档附加到电子邮件中?

I'm sending an email using the cfmail tag, and trying to attach a PDF file from a URL:

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
   <cfmailparam file="http://myfilelocation/pdfFile.pdf">
   Body of the email
</cfmail>

However, this is not working. Without the cfmailparam tag, the email sends successfully. If I go to http://myfilelocation/pdffile.pdf, I see the PDF document that I'm trying to attach. Am I doing something wrong? How can I attach a PDF document to an email from a URL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

德意的啸 2024-11-26 05:26:26

如果您要发送 HTML 电子邮件,为什么不直接链接到 PDF?这使得电子邮件变得更小,并且即使在 PDF 发出后您也有机会更新 PDF。

If your are send HTML email, why not just link to the PDF directly? This makes for smaller emails and gives you a chance to update the PDF even after it is sent out.

伴我老 2024-11-26 05:26:26

cfmailparam 文件 应指向您服务器上的某个位置。然后将该文件附加到电子邮件中:

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
<cfmailparam file="d:\websites\mysite\resources\pdf1.pdf">
   Body of the email
</cfmail>

The cfmailparam file should point to a location on your server. This file is then attached to the email:

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
<cfmailparam file="d:\websites\mysite\resources\pdf1.pdf">
   Body of the email
</cfmail>
○闲身 2024-11-26 05:26:26

您可以使用 CFHTTP 将文件检索到服务器并使用 getTempFile() || getTempDirectory() 临时存储该文件,最后使用 CFMAILPARAM 附加该文件。

编辑:

<cfset tempFile = getTempDirectory(getTempFile()) />
<cfhttp url="http://myfilelocation/pdfFile.pdf" method="get" file="#tempFile#"></cfhttp>

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
   <cfmailparam file="#tempFile#">
   Body of the email
</cfmail>

未测试

You can use CFHTTP to retrieve your file to your server and getTempFile() || getTempDirectory() to temporary stock this file and finally use CFMAILPARAM to attach this file.

Edit:

<cfset tempFile = getTempDirectory(getTempFile()) />
<cfhttp url="http://myfilelocation/pdfFile.pdf" method="get" file="#tempFile#"></cfhttp>

<cfmail to="[email protected]" from="[email protected]" subject="Subject" type="html">
   <cfmailparam file="#tempFile#">
   Body of the email
</cfmail>

Not tested

相对绾红妆 2024-11-26 05:26:26

您的代码仅适用于文本文件。对于其他文件,我们需要进行数据转换。参见下文:

<cfhttp method="get" url="http://myfilelocation/pdfFile.pdf">
<!---conversion--->
<cfif IsSimpleValue(cfhttp.Filecontent)>
    <cfset content = cfhttp.Filecontent>
<cfelse>
    <cfset content = cfhttp.Filecontent.toByteArray()>
</cfif>

cfmailparam 如下:

<cfmailparam file="#fileNameOfYourChoice#" type="#cfhttp.Mimetype#" content="#content#" />

这适用于特殊 URL(例如: http://myfilelocation/pdfFile.pdf ?querystring=1http://myfilelocation/notPdfFileName/)并允许我们根据需要命名文件

Your code will work fine for text files only. For other files we need conversion of data. See below:

<cfhttp method="get" url="http://myfilelocation/pdfFile.pdf">
<!---conversion--->
<cfif IsSimpleValue(cfhttp.Filecontent)>
    <cfset content = cfhttp.Filecontent>
<cfelse>
    <cfset content = cfhttp.Filecontent.toByteArray()>
</cfif>

And cfmailparam like:

<cfmailparam file="#fileNameOfYourChoice#" type="#cfhttp.Mimetype#" content="#content#" />

This works with special URLs(eg: http://myfilelocation/pdfFile.pdf?querystring=1 or http://myfilelocation/notPdfFileName/) and also allow us to name the file as we need

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文