【问题标题】:Email: how to set a name of the embedded image in C# / System.Mail?电子邮件:如何在 C#/System.Mail 中设置嵌入图像的名称?
【发布时间】:2012-04-23 20:48:47
【问题描述】:

我正在尝试从 C# 发送带有嵌入图像的电子邮件。当我在 Gmail 中收到这封电子邮件时,嵌入的图像没有正确的名称 - 相反,它们显示为“noname” - 请参见下面的屏幕截图

这是我将图像嵌入电子邮件的方法:

foreach (var objimage in images)
{
    var ms = new MemoryStream(objimage.ImageBytes);
    var lr = new LinkedResource(ms, MediaTypeNames.Image.Jpeg);
    lr.ContentId = "Photo_" + (++i).ToString();
    lstImages.Add(lr);

    body += string.Format("<img src='cid:{0}' alt='{1}' name='{1}' title='{1}' />", lr.ContentId, objimage.ImageName);
}

看这个问题:How to stop embedded images in email being displayed as attachments by GMail? - 并比较我的电子邮件正文,看起来我需要将 Content-Type 字段设置为

内容类型:图片/jpeg; name="我的图片名称.png""

而目前我的电子邮件是这样的:

----boundary_3_d581d04c-d294-4dc5-971e-785a678fbd12
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <Photo_1>

知道如何使用 C# 和 System.Mail 做到这一点吗?

谢谢。

【问题讨论】:

    标签: c# html-email mime-message


    【解决方案1】:

    嗯,答案很简单:

    lr.ContentType.Name = "my image name.jpg";
    

    感谢Send html email with embedded image and plain text with same image as attachment in C#

    【讨论】:

      【解决方案2】:

      如果图像没有进入 IE 使用下面 linkedResource = new LinkedResource(src, MediaTypeNames.Image.Jpeg); //abbukmailer.com

      【讨论】:

        【解决方案3】:

        附件

        Content-Disposition: attachment; fileName=<Your file name>
        

        关于 RFC

        对于链接资源必须是类似的东西

        【讨论】:

          猜你喜欢
          • 2011-11-01
          • 2018-12-24
          • 2010-12-23
          • 2012-04-27
          • 2020-07-28
          • 2011-10-06
          • 2015-01-29
          相关资源
          最近更新 更多