ABCpdf 将文档附加到电子邮件
我已经使用 ABDpdf 渲染 pdf 并将其流式传输到浏览器,但我想知道是否可以将渲染的 pdf 附加到电子邮件中。有人这样做过吗?
我希望有一种方法不需要我将 pdf 保存到临时目录然后附加文件,然后删除它。
I've used ABDpdf to render a pdf and stream it to the browser, but I'm wondering if I can attach the rendered pdf to an email. Has anyone ever done that?
I'm hoping there is a way that doesn't require me to save the pdf to a temp directory then attach the file, then delete it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Meklarian 是对的,但需要指出的一点是,将 pdf 保存到流中后,您需要将流位置重置回 0。否则发送的附件将全部被 foo-barred。
(我花了大约两个小时才弄清楚。哎呀。希望能帮助其他人节省一些时间。)
Meklarian is right, but one little thing to point out, is that after you've saved the pdf into your stream, you will want to reset your stream position back to 0. Otherwise the attachment that is sent will be all foo-barred.
(It took me about two hours to figure it out. Ouch. Hope to help someone else save some time.)
根据 ABCpdf PDF 支持站点上的文档,存在支持保存到流的 Doc() 对象的重载。借助此功能,您可以将结果保存为生成的 PDF,而无需使用 MemoryStream 类显式写入磁盘。
.NET 的 ABCpdf PDF 组件:Doc.Save()
MemoryStream (System.IO) @ MSDN
创建 MemoryStream 后,您可以将该流传递给任何支持从流创建附件的电子邮件提供商。 System.Net.Mail 中的 MailMessage 对此提供支持。
MailMessage 类 (System.Net .Mail)@MSDN
MailMessage.Attachments 属性@MSDN
附件类 @ MSDN
附件构造函数 @ MSDN
最后,如果您以前从未使用过 MailMessage 类,请使用 SmtpClient 类来发送消息。
SmtpClient 类 (System.Net .邮件)
According to the documentation on the ABCpdf PDF support site, there is an overload of the Doc() object that supports saving to a stream. With this feature, you can save the results a generated PDF without explicitly writing to disk by using the MemoryStream class.
ABCpdf PDF Component for .NET : Doc.Save()
MemoryStream (System.IO) @ MSDN
With a MemoryStream created, you may then pass the stream on to any email provider that supports creating attachments from a stream. MailMessage in System.Net.Mail has support for this.
MailMessage Class (System.Net.Mail) @ MSDN
MailMessage.Attachments Property @ MSDN
Attachments Class @ MSDN
Attachments Constructor @ MSDN
Finally, if you've never used the MailMessage class before, use the SmtpClient class to send your message on its way.
SmtpClient Class (System.Net.Mail)