将写内容过程经常用的内容段备份一次,下面的内容是关于C#发送内置图片的html格式邮件的内容,应该对码农们也有用处。
MailMessage m = new MailMessage();
m.Subject = "html email with embedded image coming!";
string htmlBody = "<html><body><h1>Picture</h1><br><img src="cid:Pic1"></body></html>";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString
(htmlBody, null, MediaTypeNames.Text.Html);
LinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg);
pic1.ContentId = "Pic1";
avHtml.LinkedResources.Add(pic1);
string textBody = "You must use an e-mail client that supports HTML messages";
AlternateView avText = AlternateView.CreateAlternateViewFromString
(textBody, null, MediaTypeNames.Text.Plain);
m.AlternateViews.Add(avHtml);
m.AlternateViews.Add(avText);
client.Send(m);
原文地址:https://www.cnblogs.com/lpyg/p/10260947.html