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("[email protected]");
message.Subject = "Subject";
message.From = new System.Net.Mail.MailAddress("[email protected]");
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()));
任何幫助如何得到這個工作?謝謝