通过电子邮件发送嵌入式图片
通过电子邮件发送图像作为身体中的嵌入式图像时出现问题。图像文件显示为可以的附件,但嵌入式图像部分仅显示为红色x。
这是我到目前为止的
LinkedResource inline = new LinkedResource(filePath);inline.ContentId = Guid.NewGuid().ToString();
MailMessage mail = new MailMessage();
Attachment att = new Attachment(filePath);
att.ContentDisposition.Inline = true;
mail.From = from_email;
mail.To.Add(data.email);
mail.Subject = "Client: " + data.client_id + " Has Sent You A Screenshot";
mail.Body = String.Format(
"<h3>Client: " + data.client_id + " Has Sent You A Screenshot</h3>" +
@"<img src=""cid:{0}"" />", inline.ContentId);
mail.IsBodyHtml = true;
mail.Attachments.Add(att);
回答:
尝试这个
string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:filename\"></body></html>"; AlternateView avHtml = AlternateView.CreateAlternateViewFromString
(htmlBody, null, MediaTypeNames.Text.Html);
LinkedResource inline = new LinkedResource("filename.jpg", MediaTypeNames.Image.Jpeg);
inline.ContentId = Guid.NewGuid().ToString();
avHtml.LinkedResources.Add(inline);
MailMessage mail = new MailMessage();
mail.AlternateViews.Add(avHtml);
Attachment att = new Attachment(filePath);
att.ContentDisposition.Inline = true;
mail.From = from_email;
mail.To.Add(data.email);
mail.Subject = "Client: " + data.client_id + " Has Sent You A Screenshot";
mail.Body = String.Format(
"<h3>Client: " + data.client_id + " Has Sent You A Screenshot</h3>" +
@"<img src=""cid:{0}"" />", att.ContentId);
mail.IsBodyHtml = true;
mail.Attachments.Add(att);
以上是 通过电子邮件发送嵌入式图片 的全部内容, 来源链接: utcz.com/qa/414067.html