我有一个由PDFTK(PDFToolkit)生成的PDF。我正在尝试将保存到downloads文件夹的ReturnedPDF添加到C#中的MailMessage
。
PDF下载没有问题;然而,附着不是那么顺利。
var pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap);
var newpdffer = PDFHelper.ReturnPDF(pdfContents, "100-" + genUUID.Text + ".pdf");
返回我填好的PDF(作为下载的文件)...但是,我似乎无法弄清楚如何在MemoryStream
中附加它。我只是想附加它并通过电子邮件发送给我。
我收到了电子邮件 - 但是我收到的附件中没有任何内容。请参阅下面的代码:
var doc = new Document();
MemoryStream memoryStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Open();
//doc.Add(new Attachment(thispdfnew));
//doc.Add(new Paragraph("Second Paragraph"));
writer.CloseStream = false;
doc.Close();
memoryStream.Position = 0;
string toemailaddress = email.Text;
string youremailadd = youremail.Text;
MailMessage mm = new MailMessage();
mm.To.Add(new MailAddress(youremail.Text));
MailAddress addressBCC = new MailAddress(email.Text);
mm.Bcc.Add(addressBCC);
mm.Subject = "New form Completed "+Preparedby.Text;
mm.Body = "To view the message, please use an HTML compatible email viewer!";
mm.Attachments.Add(new Attachment(memoryStream, "100-" + genUUID.Text + ".pdf"));
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("postmaster@this.com", "343543");
client.Host = "smtp.mailchimp.org";
client.Send(mm);
我花了最后一天谷歌搜索并试图弄清楚如何将生成的PDF放入邮件流消息,但似乎无法搞清楚。我正在使用PDFTK,它使用iTextSharp来解析PDF。