ASP.NET MVC 发送电子邮件附件
我有一个控制器操作,可以生成 PDF 并将其流式传输到客户端,但也希望有一个控制器操作,可以将 PDF 下载操作的输出作为附件通过电子邮件发送。我知道如何发送电子邮件,问题是如何使用/捕获电子邮件附件的 MVC 下载操作。
伪代码:
public PdfResult Download(int? someId)
{
var pdfBuilder = new pdfBuilder();
var pdfStream = pdfBuilder.StreamPdf(someId);
return new PdfResult("someId.pdf", "application/pdf", pdfStream);
}
public ActionResult Email(int? someId)
{
var pdfStream = View("Download", someId);
var attachment = new Attachment(pdfStream, "someId.pdf");
//...send email code
}
I have a controller action which generates and streams a PDF to the client, but would also like to have a controller action which emails the output of that PDF download action as an attachment. I know how to send an email, the question is how can I use/capture that MVC download action for my email attachment.
Pseudo code:
public PdfResult Download(int? someId)
{
var pdfBuilder = new pdfBuilder();
var pdfStream = pdfBuilder.StreamPdf(someId);
return new PdfResult("someId.pdf", "application/pdf", pdfStream);
}
public ActionResult Email(int? someId)
{
var pdfStream = View("Download", someId);
var attachment = new Attachment(pdfStream, "someId.pdf");
//...send email code
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试添加一个辅助类来返回 PdfResult,而不是在 Email() 方法中调用 Download()。
You might try to add a helper class to return the PdfResult instead of calling Download() in your Email() method.