C#發送內置圖片的html格式郵件的代碼
將寫內容過程經常用的內容段備份一次,下面的內容是關於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);
C#發送內置圖片的html格式郵件的代碼