我有生成 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/