作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有生成 pdf 文件的代码,我想将它作为电子邮件的附件发送。
我有这个代码:
FileContentResult fileContentResult = File(fileName, "application/pdf", "file.pdf");
我有这个代码可以通过电子邮件发送附件
Attachment a = new Attachment();
sender.SendMail("a@a.com", "a@a.com", "subject", "Body", a);
如何将 FileContentResult 转换为 Attachment 对象?
最佳答案
你试过用这个吗:Attachment Constructor (Stream, ContentType) ?
有点像
MemoryStream ms = new MemoryStream(fileContentResult.FileContents);
// Create an in-memory System.IO.Stream
ContentType ct = new ContentType(fileContentResult.ContentType);
Attachment a = new Attachment(ms, ct);
关于c# - 如何从 C# 发送生成的 pdf 文件作为电子邮件中的附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3294620/
我是一名优秀的程序员,十分优秀!