如何发送生成的PDF文件从C#中的电子邮件附件? [英] How to send generated pdf file as attachment in email from C#?

查看:642
本文介绍了如何发送生成的PDF文件从C#中的电子邮件附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成的PDF文件代码,我想将它作为附件发送到电子邮件。

i have code that generates a pdf file and i want to send it as an attachment to an email .

我有这样的代码:

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

和我有这个代码的电子邮件附件

and i have this code to email an attachment

        Attachment a = new Attachment();
        sender.SendMail("a@a.com", "a@a.com", "subject", "Body", a);



我如何转换的 FileContentResult 附件对象

推荐答案

您是否尝试过使用这样的:的附件构造函数(流,则contentType)

Have you tried using this: 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);

这篇关于如何发送生成的PDF文件从C#中的电子邮件附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆