c# - 如何从 C# 发送生成的 pdf 文件作为电子邮件中的附件?

标签 c# email

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

相关文章:

java - 为什么 EditText.getText() 的 Xamarin 等价物返回一个字符串?

c# - 我如何使用 OpenXML C# 水平合并 Microsoft Word 表格单元格

.net - 如何将正文中包含不同文本的电子邮件发送给多个收件人

python - 如何更改服务器上的最大邮件大小限制?

iphone - 如何在不显示邮件编辑器 View 的情况下发送邮件

c# - ASP.NET HttpContext.Current.Session 突然总是空的

c# - 如何从解析依赖项将参数传递到 Autofac 模块

c# - 在 Windows 窗体中加载没有 CrystalReportViewer 的 Crystal 报表模板

javascript - 尝试通过 RingCentral 通过网页抓取或通过电子邮件发送 .csv 导出来生成自动每日通话报告

.net - 在 .NET 中创建电子邮件