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

2024-04-16

我有生成 pdf 文件的代码,我想将其作为电子邮件的附件发送。

我有这个代码:

        FileContentResult fileContentResult = File(fileName, "application/pdf", "file.pdf");

我有这个代码可以通过电子邮件发送附件

        Attachment a = new Attachment();
        sender.SendMail("[email protected] /cdn-cgi/l/email-protection", "[email protected] /cdn-cgi/l/email-protection", "subject", "Body", a);

我如何转换文件内容结果 into a 依恋 object?


您是否尝试过使用这个:附件构造函数(流、内容类型) http://msdn.microsoft.com/en-us/library/ab7hb4y5.aspx?

就像是

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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 C# 将生成的 pdf 文件作为电子邮件附件发送? 的相关文章

随机推荐