包含静态 Google 地图的电子邮件在 Gmail 中无法正确显示
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您的编码有点不对劲 - 您想要对单个值进行编码,而不是整个查询字符串。
更重要的是,Google 在此引导术语“google 地图静态 gmail”,因此我还想提供以下建议:
例如,
我希望我有文档来支持这一点(如果存在),甚至是我第一次阅读它的线程的链接,这样我就可以给出正确的归属 - 如果您知道,请编辑。无论哪种情况,它都对我有用!
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:
e.g.
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!
也许由于某种原因,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... :-)