如何将文件附加到来自 URL 的电子邮件?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您要发送 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.
cfmailparam 文件
应指向您服务器上的某个位置。然后将该文件附加到电子邮件中:The
cfmailparam file
should point to a location on your server. This file is then attached to the email:您可以使用 CFHTTP 将文件检索到服务器并使用 getTempFile() || getTempDirectory() 临时存储该文件,最后使用 CFMAILPARAM 附加该文件。
编辑:
未测试
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:
Not tested
您的代码仅适用于文本文件。对于其他文件,我们需要进行数据转换。参见下文:
cfmailparam 如下:
这适用于特殊 URL(例如: http://myfilelocation/pdfFile.pdf ?querystring=1 或 http://myfilelocation/notPdfFileName/)并允许我们根据需要命名文件
Your code will work fine for text files only. For other files we need conversion of data. See below:
And cfmailparam like:
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