来自 Rails 的电子邮件,其图像位于 AWS 的回形针中,正在发生一件非常奇怪的事情

发布于 2024-10-18 00:02:45 字数 827 浏览 2 评论 0原文

我正在从 Rails 发送电子邮件,电子邮件中包含图像。这些图像通过回形针存储在 AWS S3 上。电子邮件会内置在视图中并动态发送...

到目前为止您支持我吗?伟大的!

当收到电子邮件时,我会说大约十分之一的图像有一个稍微不正确的 src="" 标签,这意味着图像没有显示。

img 标签的 src 属性的问题是它在某处随机插入了一个“+”符号。顺便说一句,这大约是十分之一的不起作用的图像。所以 src 属性在电子邮件的源中看起来像这样......

http://s3.ama+zonaws.com/bucketname/attachments/ect...
http://s3.amazonaws.com/bu+cketname/attachments/ect...
http://s3.amazonaws.com/bucketname/attachm+ents/ect...

你看!随机+的。什么可能导致 src 字符串发生这种情况?

干杯!

编辑:

他是输出图像的代码示例,

<%= image_tag xxxxx.image.url(:thumb), :style => "display:block; padding:0; line-height:0;" %>

如果你问我的话,这是相当标准的。

另外要注意的是,我已经检查了控制台中的输出 html,并且 src 中没有 + 。

...我尝试过发送几个不同的电子邮件提供商(gmail、hotmail、me.com 等)和客户端,但所有这些都出现了问题。

I am sending out emails from rails, in the emails are images. Those images are stored on AWS S3 via paperclip. The email gets built in the view and sent dynamically...

Are you with me so far? Great!

When the emails are received I would say approx one out of ten of the images have a slightly incorrect src="" tag which means the images arn't showing.

The problem with src attribute of the img tag is it has a "+" sign randomly inserted in it somewhere. This is about one out of ten images that don't work by the way. So the src attribute will look something like this in the source of the email...

http://s3.ama+zonaws.com/bucketname/attachments/ect...
http://s3.amazonaws.com/bu+cketname/attachments/ect...
http://s3.amazonaws.com/bucketname/attachm+ents/ect...

You see! Randome +'s. What could possibly be causing this to happen to the src string?

Cheers!

Edit:

His a sample of the code that's outputting the image,

<%= image_tag xxxxx.image.url(:thumb), :style => "display:block; padding:0; line-height:0;" %>

Pretty standard if you ask me.

Also to note I've checked the output html in the console and that doesn't have the +'s in the src.

...and I've tried it sending several different email providers (gmail, hotmail, me.com ect) and clients, the problem occurs on all of them.

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

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

发布评论

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

评论(1

忆依然 2024-10-25 00:02:45

我以前在从 .NET 应用程序发送电子邮件时遇到过类似的情况。我不能保证这是同一个问题,因为我对这里发生的内部魔法一无所知,但希望这会有所帮助。

SMTP 在邮件流中具有行长度限制,因此如果您的邮件太长,SMTP 服务器可能会断行。我认为限制是 1000 个字符,但并非所有服务器都可以正确实现该协议。

在某些情况下,服务器还会在换行符处插入一个字符,最常见的是 !blank。如果在图像 URL 中插入空白字符,客户端软件可能会将其编码为 +

尝试在每个图像后插入 cr+lf 换行符,看看问题是否有所改善。

I've encountered something similar before when sending email from a .NET application. I can't vouch this is the same issue since I don't know anything about the internal magic occurring here, but hope this helps.

SMTP has a line length limitation in the message stream, so if your message is too long, the SMTP server may break the line. I think the limitation is 1000 characters, but not all servers might implement the protocol correctly.

In some cases the server also inserts a character at the line break, most commonly ! or blank. If the blank character is inserted inside the image URL, the client software would likely encode it to +.

Try inserting cr+lf line breaks after each image, and see if the issue improves.

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