【发布时间】:2017-08-10 19:45:35
【问题描述】:
我正在使用以下代码 (C#) 将图像嵌入到 html 电子邮件中:
Bitmap image = new Bitmap();
// set something to image
MemoryStream ms = new MemoryStream();
image.Save(ms, ImageFormat.Jpeg);
ContentType contentType = new ContentType(MediaTypeNames.Image.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
Attachment attachment = new Attachment(ms, contentType);
attachment.ContentId = "image@email";
MailMessage mail = new MailMessage();
mail.From = new MailAddress("...");
mail.To.Add("...");
mail.Subject = "...";
mail.Body = body; // view below
mail.IsBodyHtml = true;
mail.Attachments.Add(attachment);
smtpClient.Send(mail);
ms.Close();
这里是html正文的相关部分:
<img align='center' alt='' src='cid:image@email' width='100' style='padding-bottom: 0; display: inline !important; vertical-align: bottom;'>";
在 gmail 网站上查看电子邮件看起来是正确的:即图像嵌入到 html 正文中。
相反,使用 Thunderbird 时,图像会作为附件接收,但不会被识别为 jpg。附件名为“第 1.2 部分”。如果我双击它,则使用计算机上安装的默认图像查看器打开图像。
为了以与最常见的电子邮件阅读器兼容的方式正确发送嵌入图像,我需要添加什么?
更新
要为附加的图像命名,添加以下内容就足够了:
attachment.Name = "name.jpg";
Thunderbird 仍然拒绝在 html 中显示它。
【问题讨论】: