簡體   English   中英

如何在C#中將動態生成的HTML作為電子郵件附件發送

[英]How to send dymanically generated html as a email attachment in C#

我正在使用以下代碼發送電子郵件,但如果使用html附件,則失敗。

System.IO.MemoryStream ms = new System.IO.MemoryStream();

System.IO.StreamWriter writer2 = new System.IO.StreamWriter(ms);
writer2.Write("<html><head></head><body>Invoice 1</body></html>");
writer2.Flush();
writer2.Dispose();

MailMessage mm = new MailMessage();
mm.To.Add("test@gmail.com");
mm.CC.Add("test2@gmail.com");
mm.From = new MailAddress("test3@gmail.com");
mm.Subject = "नोटिस";
mm.Body = sb.ToString();

System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Html);
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, ct);
attach.ContentDisposition.FileName = "myFile.html";
mm.Attachments.Add(attach);
mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "rcms.pdf"));
ms.Close();
mm.IsBodyHtml = true;                   

只需要一行。

var a = System.Net.Mail.Attachment.CreateAttachmentFromString(“ ‌́'” + sb.ToString()+“'<‌́ / body>”,“ notices.html”);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM