GMail 未显示我使用 System.Net.Mail 发送的内联图像 (cid)

2023-11-22

当我通过 Outlook 或 gmail 向 gmail 电子邮件地址发送电子邮件时,我可以添加直接显示在 gmail 网络界面中的内联图像:

GMail webinterface with working inline image

工作电子邮件的相关原始邮件标头和原始正文部分:

--089e0158b6909948880520cef593
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Image there?<div><img src=3D"cid:ii_if3zqhar0_15014363be0a=
41b2" width=3D"10" height=3D"3"><br>=E2=80=8BHope so!<br></div></div>

--089e0158b6909948880520cef593--
--089e0158b69099488c0520cef594
Content-Type: image/png; name="test.png"
Content-Disposition: inline; filename="test.png"
Content-Transfer-Encoding: base64
Content-ID: <ii_if3zqhar0_15014363be0a41b2>
X-Attachment-Id: ii_if3zqhar0_15014363be0a41b2

iVBORw0KGgoAAAANSUhEUgAAAAoAAAADCAIAAAAlXwkiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAADFJREFUeNpi+A8BDCf/wwDD/1VIbBABIudDmAchokwgag9QAiwHVcsM
Z/5fCdYJEGAAuthJ+AVi5KgAAAAASUVORK5CYII=
--089e0158b69099488c0520cef594--

完整的工作原始电子邮件:工作原始电子邮件.

但是,当我通过发送这样的电子邮件时System.Net.Mail from .NET它不适用于 gmail 网络界面,但适用于任何其他电子邮件客户端(outlook、iphone 等):

GMail webinterface with not working inline image

非工作电子邮件的相关原始邮件标头和原始正文部分:

----boundary_3_6a0761ee-57e2-4bdd-b1f1-7302b3c8a7a1
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Image there?<br /><img src=3D"cid:[email protected]" /><=
br />Hope so!
----boundary_3_6a0761ee-57e2-4bdd-b1f1-7302b3c8a7a1--

----boundary_5_979e00c0-3fb9-46a0-b25c-1cee82cc15eb
Content-Type: image/png; name=test.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=test.png
Content-ID: <[email protected]>

iVBORw0KGgoAAAANSUhEUgAAAAoAAAADCAIAAAAlXwkiAAAAGXRFWHRTb2Z0d2FyZQBB
ZG9iZSBJbWFnZVJlYWR5ccllPAAAADFJREFUeNpi+A8BDCf/wwDD/1VIbBABIudDmAch
okwgag9QAiwHVcsMZ/5fCdYJEGAAuthJ+AVi5KgAAAAASUVORK5CYII=
----boundary_5_979e00c0-3fb9-46a0-b25c-1cee82cc15eb--

完整的非工作原始电子邮件:非工作原始电子邮件.

这是我发送内联图像的代码:

SmtpClient client = new SmtpClient("real.server.on.the.internet");
MailMessage mail = new MailMessage("Flattiverse <[email protected]>", "Ghostie <[email protected]>");
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.SubjectEncoding = System.Text.Encoding.UTF8;

AlternateView plainView = AlternateView.CreateAlternateViewFromString("Please view as HTML-Mail.", System.Text.Encoding.UTF8, "text/plain");
plainView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;

AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Image there?<br /><img src=\"cid:[email protected]\" /><br />Hope so!", System.Text.Encoding.UTF8, "text/html");
htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);

mail.Subject = "7";

Attachment attachment = new Attachment("test.png", "image/png");
attachment.ContentId = "[email protected]";
attachment.ContentDisposition.Inline = true;
attachment.ContentDisposition.DispositionType = "inline; filename=test.png";
mail.Attachments.Add(attachment);

client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("working_username", "working_password");
client.Send(mail);

我还尝试了 GMail 格式的 cid(例如ii_012345678_9abcdef0123456789)以及其他相关问题中所述的许多其他内容。 (在邮件正文等中使用 ' 代替 ")

问题:我做错了什么,GMail 不显示我的内嵌图像?我需要如何更改我的代码?也许我想要的无法实现System.Net.Mail?


添加为附件时,内联图像在 GMail Web 界面中会被忽略。将图像添加为备用视图时,Outlook 会忽略该图像。

要添加与 GMail Web 界面和 Outlook(以及 iPhone 邮件客户端)兼容的内嵌图像,您必须将其添加为LinkedResource.

问题中的示例代码必须像这样修复:

SmtpClient client = new SmtpClient("real.server.on.the.internet");
MailMessage mail = new MailMessage("Flattiverse <[email protected]>", "Ghostie <[email protected]>");
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.SubjectEncoding = System.Text.Encoding.UTF8;

LinkedResource image = new LinkedResource("test.png", "image/png");
image.ContentId = "[email protected]";
image.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
image.ContentType.Name = "[email protected]";
image.ContentLink = new Uri("cid:[email protected]");

AlternateView plainView = AlternateView.CreateAlternateViewFromString("Please view as HTML-Mail.", System.Text.Encoding.UTF8, "text/plain");
plainView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;

AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Image there?<br /><img src=\"cid:[email protected]\" /><br />Hope so!", System.Text.Encoding.UTF8, "text/html");
htmlView.LinkedResources.Add(image);
htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);

mail.Subject = "15";

client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("working_username", "working_password");
client.Send(mail);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GMail 未显示我使用 System.Net.Mail 发送的内联图像 (cid) 的相关文章

随机推荐

  • AVRO 中的数据验证

    我是 AVRO 新手 如果这是一个简单的问题 请原谅 我有一个使用 AVRO 模式进行记录调用的用例 假设我有 avro 架构 name abc namepsace xyz type record fields name CustId ty
  • 既然他们停止为 Eclipse 开发 derby 插件,是否可以在 Eclipse 中使用 apache 的 derby ?

    我想使用 apache 中的 Derby 以便在我当前正在开发的桌面应用程序上包含数据库管理 不幸的是 我发现他们已经停止开发这个插件 并且我在网上阅读的所有教程都引用了这个插件 所以我的问题是 如何在 eclipse 上使用最新版本的 D
  • Jenkinsfile 中的故障后块不起作用

    我正在尝试使用并行步骤进行失败后操作 但它永远不会起作用 这是我的 Jenkins 文件 pipeline agent any stages stage test steps withMaven maven maven3 Maven ins
  • 如何在 LLDB 断点条件下使用堆栈内容?

    问题 我遇到过这样一种情况 我们在启动期间进行媒体播放 并且 objc exception throw 在此期间点击了大约 5 次 但总是被捕获 并且它是way媒体播放器对象的南边 我厌倦了 a 必须手动继续 n 次 或 b 必须禁用断点直
  • 将 Textview 添加到 FrameLayout 的确定位置

    我正在尝试添加一个textView to a frameLayout The TextView has wrap content属性 因此它会随着文本的增长而增长 我将其添加到FrameLayout有了这个功能 FrameLayout fi
  • Java中从磁盘备份和恢复sqlite到内存

    我正在尝试将 sqlite 文件读入内存以获得更好的性能 当关闭我的应用程序时 我想将其写回硬盘 我正在使用jdbc 3 7 2 Java 驱动程序 根据文档 我的代码看起来像 this conn DriverManager getConn
  • 如何使用自动布局在 MKAnnotation 中显示多行?

    我正在使用 Mapkit 如何多行输入MK注释视图 每个注释都有标题和副标题 我如何在以下的帮助下显示多行副标题自动布局 我找到了答案 请尝试我的答案 我们只需要编写代码 MKAnnotationView mapView MKMapView
  • Jade:加载外部javascript并调用函数

    我正在学习 Express Node Jade 现在在 Jade 文件中我想包含一个来自公共文件夹的 javascript 文件 仅用于该页面 例如 在 jade 文件中我输入以下内容 script src javascripts test
  • Delphi XE2 FireMonkey 是否支持 Indy 跨平台应用程序?

    看看带有 Firemonkey 的新 Delphi XE2 考虑到它是针对 Windows Mac OSX 和 iOS 进行编译的 VCL 组件在 FireMonkey 应用程序中毫无用处 我的问题是 是否有 将会有 Indy Firemo
  • 如何从 Dart http 调用返回 json / 如何完全使用流?

    这是我的代码 应该返回 json 我从这里改编了这段代码https github com flutter flutter issues 15110 Stream defaultReturn HttpClientResponse httpCl
  • MissingSecret [MissingSecretError]:请在生产中定义一个“秘密”

    根据文档https next auth js org configuration options secret 添加一个NEXTAUTH 秘密作为环境变量 您不必定义此选项 但在 vercel 制作中我仍然得到 2022 03 24T10
  • 访问元组中元素的时间复杂度

    关于哈希 字典 和列表也有类似的问题 这里还有一条很好的信息 http wiki python org moin TimeComplexity 但我没有找到任何关于元组的信息 访问时间为 data structure i 对于链表来说一般是
  • 如何更改指针的默认图像

    我需要使用一些自定义图像更改光标 指针的默认图像 创建一个类并指定光标的悬停值不是一个有效的解决方案 因为我必须将该类添加到所有已创建的元素中 并且您知道吗 这并不完全是最佳的 也无法将该类添加到主体中 因为带有光标的子级 指针会覆盖它 知
  • 清除 Python 的命令行输出 [Eclipse]

    我正在使用 Eclipse 编写 Python 并且我希望能够轻松地清除屏幕 我见过这个问题 并尝试了 除其他建议外 以下解决方案 import os def clear os system cls if os name nt else c
  • vector> 无法使用 MSVC 进行编译

    制作仅移动类型的地图向量似乎在 Windows 上无法正常工作 请参阅此处的代码 https godbolt org z yAHmzh include
  • Golang 的 SQL 包无法进行即席/探索性查询吗?

    根据文档 从 Go 中的数据库中获取数据的唯一方法似乎是使用 Rows Scan 这意味着您必须在编译时知道所有列的计数和类型 我错过了什么吗 您应该如何支持即席查询 或者甚至从表中取出将来可能发生变化的所有列 The sql Rows类型
  • 图像未显示在托管网站中

    感谢您花时间查看此内容 我已尽我所能进行研究 但没有提出任何建议 我看到一个类似的堆栈溢出帖子 关于等待图像完成处理 但我已经等了大约 2 5 小时 图像仍然丢失 我正在将 AngularFire 与 Firebase 一起使用 我正在使用
  • 使用“base”是否是一种不好的做法,即使它可能有利于可读性?

    我知道这是一个主观问题 但我总是对编码风格的最佳实践感到好奇 ReSharper 4 5 在实现类中调用基本方法之前向我发出有关关键字 base 的警告 即 base DoCommonBaseBehaviorThing 虽然我欣赏 越少越好
  • 将多个 -std 开关传递给 g++

    假设运行是否安全g with g std c 98 std c 11 会使用C 11编译吗 我在中没有找到明确的确认文档 但我看到 O标志的行为是这样的 The 海湾合作委员会手册没有说明 任何互斥的最后一个 std 指定的选项生效 第一次
  • GMail 未显示我使用 System.Net.Mail 发送的内联图像 (cid)

    当我通过 Outlook 或 gmail 向 gmail 电子邮件地址发送电子邮件时 我可以添加直接显示在 gmail 网络界面中的内联图像 工作电子邮件的相关原始邮件标头和原始正文部分 089e0158b6909948880520cef5