[C#] C#发送内置图片的html格式邮件 →→→→→进入此内容的聊天室

来自 , 2021-01-08, 写在 C#, 查看 149 次.
URL http://www.code666.cn/view/c36b1132
  1. MailMessage m = new MailMessage();
  2. m.From = new MailAddress("ir@sharejs.com", "Raja Item");
  3. m.To.Add(new MailAddress("su@sharejs.com", "Sekaran Uma"));
  4. m.Subject = "html email with embedded image coming!";
  5.  
  6. // Create the HTML message body
  7. // Reference embedded images using the content ID
  8. string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:Pic1\"></body></html>";
  9. AlternateView avHtml = AlternateView.CreateAlternateViewFromString
  10.     (htmlBody, null, MediaTypeNames.Text.Html);
  11.  
  12. // Create a LinkedResource object for each embedded image
  13. LinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg);
  14. pic1.ContentId = "Pic1";
  15. avHtml.LinkedResources.Add(pic1);
  16.  
  17. // Create an alternate view for unsupported clients
  18. string textBody = "You must use an e-mail client that supports HTML messages";
  19. AlternateView avText = AlternateView.CreateAlternateViewFromString
  20.     (textBody, null, MediaTypeNames.Text.Plain);
  21.  
  22. m.AlternateViews.Add(avHtml);
  23. m.AlternateViews.Add(avText);
  24.  
  25. // Send the message
  26. SmtpClient client = new SmtpClient("smtp.sharejs.com");
  27. client.Send(m);
  28. //csharp/7759

回复 "C#发送内置图片的html格式邮件"

这儿你可以回复上面这条便签

captcha