在电子邮件中插入图片

时间:2015-05-09 02:13:22

标签: c# asp.net email

我正在尝试在此http://www.codeproject.com/Tips/326346/How-to-embed-a-image-in-email-body后的电子邮件中插入图片 但是有些图片没有显示在邮件中。 这是代码。

var message = new MailMessage();                
message.From = new MailAddress("noreply@happy.com");

message.To.Add("testmail@gmail.com");
var body = new StringBuilder();

message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
var path = @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg";
AlternateView altView = AlternateView.CreateAlternateViewFromString("testing mail: <img src=cid:myImage>", null, MediaTypeNames.Text.Html);
LinkedResource imageToSend = new LinkedResource(path);
imageToSend.ContentId = "myImage";

altView.LinkedResources.Add(imageToSend);
message.AlternateViews.Add(altView);


var smtp = new SmtpClient();
smtp.Send(message);

0 个答案:

没有答案