0
下面我添加了附件的截圖,因爲它顯示在電子郵件中。如何將我的PDF電子郵件附件作爲PDF正確連接?
它可以在任何PDF閱讀器中打開。
我如何獲得它作爲一個實際的PDF呈現?我感覺好像我已經錯過了一些小...
這裏是我的代碼:
public ActionResult SendInvoice(SendInvoiceViewModel model)
{
var Invoice = db.Invoices.FirstOrDefault(x => x.Id == model.Id);
MemoryStream ms = new MemoryStream(Invoice.Document);
Attachment Data = new Attachment(ms, MediaTypeNames.Application.Pdf);
ContentDisposition Disposition = Data.ContentDisposition;
Disposition.CreationDate = Invoice.Date;
Disposition.ModificationDate = Invoice.Date;
Disposition.ReadDate = Invoice.Date;
SendInvoiceMail(model.EmailAddress, Invoice.Number, model.EmailMessage, Data);
}
private void SendInvoiceMail(string emailAddress, string invoiceNumber, string message, Attachment attachment)
{
using (MailMessage Message = new MailMessage())
{
Message.From = new MailAddress("[email protected]###########");
Message.Subject = String.Format("Your store invoice {0}", invoiceNumber);
Message.To.Add(new MailAddress(emailAddress));
Message.Body = message;
Message.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient("mail.############", 587);
smtp.Credentials = new NetworkCredential("[email protected]##########", "##########");
smtp.Send(Message);
};
}
所以我錯過了什麼?
我可能看不到正確的,但你在哪裏設置你的文件名? – Mekap
我不......不知道該怎麼做,但是按照下面的奧爾瓊斯的回答,我敢打賭,我在'Attachment() – Ortund