包含静态 Google 地图的电子邮件在 Gmail 中无法正确显示

发布于 2024-10-27 01:20:52 字数 856 浏览 6 评论 0原文

我正在使用 C# 代码生成电子邮件。

在消息正文中,我想添加静态 Google 地图。为了创建静态 URL,我有以下代码

string addr = "111 Remote Drive  Cary,NC 27511";
string mapU = "http://maps.google.com/maps/api/staticmap?center=" + 
addr + HttpUtility.HtmlEncode("&zoom=14&size=512x512&maptype=roadmap&sensor=false&markers=color:green|") +
 addr;

此字符串 mapU 作为 img 标记的 src 添加到消息正文中。

当电子邮件发送到 Google Mail 帐户时,不会显示静态图像。检查损坏图像上的元素,

<img src="http://maps.google.com/maps/api/staticmap?center=111+Remote+Drive++Cary%2CNC+27511%26zoom%3D14%26size%3D512x512%26maptype%3Droadmap%26sensor%3Dfalse%26markers%3Dcolor:green%7C111+Remote+Drive++Cary,NC+27511">

Gmail 正在用 %3D 替换“=”,这似乎破坏了这一点。

向 Hotmail 发送完全相同的邮件是可行的。图像按预期显示在正确的位置。 Hotmail 保持“=”不变。

你知道 Gmail 发生了什么吗?建议如何解决这个问题?

谢谢 阿比

I am using C# code to generate an email message.

In the body of the message, I want to add a static Google map. To create the static URL, I have the following code

string addr = "111 Remote Drive  Cary,NC 27511";
string mapU = "http://maps.google.com/maps/api/staticmap?center=" + 
addr + HttpUtility.HtmlEncode("&zoom=14&size=512x512&maptype=roadmap&sensor=false&markers=color:green|") +
 addr;

This string mapU is added to the message body as a src for an img tag.

When the email is sent to a Google Mail account, the static image is not displayed. Inspect element on broken image has

<img src="http://maps.google.com/maps/api/staticmap?center=111+Remote+Drive++Cary%2CNC+27511%26zoom%3D14%26size%3D512x512%26maptype%3Droadmap%26sensor%3Dfalse%26markers%3Dcolor:green%7C111+Remote+Drive++Cary,NC+27511">

Gmail is replacing '=' with %3D, which seems to be breaking this.

Sending the exact same message to Hotmail works. The image is displayed in the correct place as expected. Hotmail is keeping '=' intact.

Any ideas what is going on with Gmail? Suggestions how this could be fixed?

Thanks
Abhi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瘫痪情歌 2024-11-03 01:20:52

看起来您的编码有点不对劲 - 您想要对单个值进行编码,而不是整个查询字符串。

更重要的是,Google 在此引导术语“google 地图静态 gmail”,因此我还想提供以下建议:

  • 要包含静态地图并使其显示在 GMail 中,您必须使用 API 密钥

例如,

<img src="https://maps.googleapis.com/maps/api/staticmap?key=KEY&sensor=false&size=200x200&zoom=12&markers=0,0" />

我希望我有文档来支持这一点(如果存在),甚至是我第一次阅读它的线程的链接,这样我就可以给出正确的归属 - 如果您知道,请编辑。无论哪种情况,它都对我有用!

It looks like your encoding is a bit off - you want to encode individual values, not the entire query string.

More importantly, Google leads here for the term "google maps static gmail", so I wanted to also offer this advice:

  • To include a static map and have it show in GMail, you must use an API key

e.g.

<img src="https://maps.googleapis.com/maps/api/staticmap?key=KEY&sensor=false&size=200x200&zoom=12&markers=0,0" />

I wish I had the doc to support that (if it exists) or even the link to the thread where I first read it so I could give proper attribution - please edit if you know. In either case, it worked for me!

浅黛梨妆こ 2024-11-03 01:20:52

也许由于某种原因,URL 编码无法正常工作.. 或者导致 gmail 因某些原因而崩溃...

删除编码并手动替换 & 。与 &;应该没问题..

抱歉,不是最优雅的解决方案...

编辑:

实际上我不知道这是否重要...但是您没有编码第一个=可能在构建后对整个URL进行编码...:-)

Maybe for some reason the URL encode is not working correctly.. or is causing gmail to freak out about something...

Remove the encode and manually replace the & with & and it should be fine..

Sorry, not the most elegant solution...

EDIT:

Actually I don't know if it matters or not... but your not encoding the first = maybe encode the entire URL after you have built it... :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文