在电子邮件正文中呈现PDF

时间:2018-02-15 13:50:15

标签: c# asp.net-mvc email pdf

我已经生成了PDF报告,我将其作为附件发送,接下来我要做的是将它们呈现在电子邮件正文中。我一直在为这一个疯狂,但找不到渲染它的方法。 到目前为止我所拥有的是:

//PDF Generation
MemoryStream workStream = new MemoryStream();
StringBuilder status = new StringBuilder("");
DateTime dTime = DateTime.Now;

Document doc = new Document();
doc.SetMargins(0 f, 0 f, 0 f, 0 f);

//Create PDF Table with 7 columns  
PdfPTable tableLayout2 = new PdfPTable(7);
doc.SetMargins(0 f, 0 f, 0 f, 50 f);

// .. some code 
//PDF Generation


PdfWriter.GetInstance(doc, workStream).CloseStream = false;
// some more code  here
byte[] byteInfo = workStream.ToArray();
workStream.Write(byteInfo, 0, byteInfo.Length);
workStream.Position = 0;

//INSTEAD OF AN ATTACHMENT HERE
message.Attachments.Add(new Attachment(workStream, "DailyReport:" + x.FirstName + x.LastName + ".pdf"));
using(SmtpClient client = new SmtpClient {
  EnableSsl = true,
    Host = "smtp.gmail.com",
    Port = 587,
    Credentials = new NetworkCredential("xxxxxxxx@xxxx.com", "xxxxxx")
}) {
  client.Send(message);
}

而不是像这样的附件:

message.Attachments.Add(new Attachment(workStream, "DailyReport:" + x.FirstName + x.LastName + ".pdf"));

我希望它在电子邮件正文中内联。

0 个答案:

没有答案