发送电​​子邮件内嵌图像 [英] Send inline image in email

查看:164
本文介绍了发送电​​子邮件内嵌图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个问题,通过电子邮件发送图像作为主体的嵌入图像。
图像文件显示作为附件是确定,但内嵌图像部分只是显示为一个红色的x。

下面是我迄今为止

  LinkedResource内嵌=新LinkedResource(文件路径);
。inline.ContentId = Guid.NewGuid()的ToString();
邮件MAILMESSAGE新= MAILMESSAGE();
附件ATT =新的附件(文件路径);
att.ContentDisposition.Inline = TRUE;
mail.From = FROM_EMAIL;
mail.To.Add(data.email);
mail.Subject =客户:+ data.client_id +向您发送了屏幕截图
mail.Body =的String.Format(
    < H3>客户:+ data.client_id +向您发送了截图< / H3>中+
    @< IMG SRC =CID:{0}/>中,inline.ContentId);mail.IsBodyHtml = TRUE;
mail.Attachments.Add(ATT);


解决方案

试试这个

 字符串htmlBody =< HTML><身体GT;< H1>图片< / H1>< BR>< IMG SRC = \\CID:文件名\\&GT ;< /身体GT;< / HTML>中;
 AlternateView avHtml = AlternateView.CreateAlternateViewFromString
    (htmlBody,空,MediaTypeNames.Text.Html); LinkedResource内嵌=新LinkedResource(filename.jpg,MediaTypeNames.Image.Jpeg);
 。inline.ContentId = Guid.NewGuid()的ToString();
 avHtml.LinkedResources.Add(内联); 邮件MAILMESSAGE新= MAILMESSAGE();
 mail.AlternateViews.Add(avHtml); 附件ATT =新的附件(文件路径);
 att.ContentDisposition.Inline = TRUE; mail.From = FROM_EMAIL;
 mail.To.Add(data.email);
 mail.Subject =客户:+ data.client_id +向您发送了屏幕截图
 mail.Body =的String.Format(
            < H3>客户:+ data.client_id +向您发送了截图< / H3>中+
            @< IMG SRC =CID:{0}/>中,inline.ContentId); mail.IsBodyHtml = TRUE;
 mail.Attachments.Add(ATT);

Having an issue sending an image via email as an embedded image in the body. The image file shows as an attachment which is ok but the inline image portion just shows as a red x.

Here is what I have so far

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);

解决方案

Try this

 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}"" />", inline.ContentId);

 mail.IsBodyHtml = true;
 mail.Attachments.Add(att);

这篇关于发送电​​子邮件内嵌图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆