using (MemoryStream stream = new MemoryStream())
{
compositeLink.PrintingSystem.ExportToPdf(stream);
Response.Clear();
Response.Buffer = false;
Response.AppendHeader("Content-Type", "application/pdf");
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.BinaryWrite(stream.GetBuffer());
Response.End();
}
我得到这个工作正常。下一步是将此 pdf 文件作为附件发送到邮件中
using (MemoryStream stream = new MemoryStream())
{
compositeLink.PrintingSystem.ExportToPdf(stream);
Response.Clear();
Response.Buffer = false;
Response.AppendHeader("Content-Type", "application/pdf");
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.BinaryWrite(stream.GetBuffer());
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("someone@example.net");
message.Subject = "Subject";
message.From = new System.Net.Mail.MailAddress("someoneelse@example.net");
message.Body = "Body";
message.Attachments.Add(Response.BinaryWrite(stream.GetBuffer()));
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("192.168.100.100");
smtp.Send(message);
Response.End();
}
我对这条线有疑问:
message.Attachments.Add(Response.BinaryWrite(stream.GetBuffer()));
任何帮助如何让它工作?谢谢