为什么 ActionMailer 随机不显示我的多部分/替代电子邮件的纯文本部分?
我正在尝试发送同时包含纯文本和 html 组件的电子邮件。没有附件,但 HTML 部分有内嵌图像。我正在使用内容类型“multipart/alternative”。我没有明确设置这些部分;我依靠文件名来确定各个部分。我正在使用 Rails 2.3.10。
大约 60% 的情况下,发送的电子邮件没有正文,并且 HTML 部分附加到名称为“noname”(无论如何在 gmail 中)的邮件中。其余时间他们按预期发送。如果我在 10 秒内发出 10 封电子邮件,几乎总是有 6 封是空白的。
当我检查日志时,收到的消息正确显示日志中的两个 mime 部分,并在内容类型声明中显示边界值。
空白电子邮件的内容类型仍然是 multipart/alternative,但没有边界,因为空白电子邮件不渲染纯文本部分,只显示 html 部分。查看正在呈现的模板,很明显消息的纯文本部分被完全跳过。
为什么这有时有效但经常失败?这些消息都是通过延迟的作业发送的。
记录“好”电子邮件:
渲染通知/_comment(0.1ms)
渲染布局/_footer (2.1ms)
渲染布局/_container (2.3ms)
渲染共享/附件/_count (0.6ms)
渲染布局/语音/_bubble (21.4ms)
渲染布局/语音/_detail (0.8ms)
呈现的通知/_comment (22.6ms)
渲染布局/_footer (2.0ms)
渲染布局/_container (2.2ms)
已发送邮件至[已编辑]日期:2010 年 11 月 8 日星期一 11:37:24 -0800
来自:“[已编辑]”<[已编辑]>
回复:“[已编辑]”[已编辑]
致:[已编辑]
主题:有人评论了你的事情
Mime 版本:1.0
内容类型:多部分/替代;边界=mimepart_4cd85174328d6_1486..fdbe5b8d87fe--mimepart_4cd85174328d6_1486..fdbe5b8d87fe
内容类型:文本/纯文本;字符集=utf-8
内容传输编码:引用-可打印
内容配置:内联【纯文本部分的内容】
<小时>[html部分的内容]
--mimepart_4cd85174328d6_1486..fdbe5b8d87fe--
空白电子邮件的日志:
渲染共享/附件/_count (0.1ms)
渲染布局/语音/_bubble (0.6ms)
渲染布局/语音/_detail (0.7ms)
渲染通知/_comment (1.6ms)
渲染布局/_footer (25.9ms)
渲染布局/_container (26.1ms)
已发送邮件至[已编辑]日期:2010 年 11 月 8 日星期一 11:37:29 -0800
来自:“[已编辑]”<[已编辑]>
回复:“[已编辑]”<[已编辑]>
致:[已编辑]
主题:有人评论了你的事情
Mime 版本:1.0
内容类型:多部分/替代;字符集=utf-8[HTML部分的内容]
请注意,这些电子邮件的发送间隔为 5 秒,并且两封电子邮件(应该)包含相同的内容。
I'm trying to send emails that have both a plain text and html component. There are no attachments, but there are inline images in the HTML part. I'm using the content-type "multipart/alternative". I'm not explicitly setting the parts; I'm relying on the filenames to determine the parts. I'm on rails 2.3.10.
Approximately 60% of the time, the emails that are sent come through with no body, and the HTML part is attached to the message with the name "noname" (in gmail anyway). The rest of the time they send as expected. If I send out 10 emails in 10 seconds, almost always 6 of them will be blank.
When I inspect the logs, the messages that come through correctly show both mime parts in the log and show a boundary value in the content-type declaration.
The blank emails still have a content-type of multipart/alternative, but no boundary, because the blank emails do not render the plain text part, and only show the html part. Looking at the templates being rendered, it's clear that the plain text part of the message is completely skipped.
Why does this sometimes work and often fail? The messages are all being sent with a delayed job.
Log for a "good" email:
Rendered notifications/_comment (0.1ms)
Rendered layouts/_footer (2.1ms)
Rendered layouts/_container (2.3ms)
Rendered shared/attachments/_count (0.6ms)
Rendered layouts/speech/_bubble (21.4ms)
Rendered layouts/speech/_detail (0.8ms)
Rendered notifications/_comment (22.6ms)
Rendered layouts/_footer (2.0ms)
Rendered layouts/_container (2.2ms)
Sent mail to [redacted]Date: Mon, 8 Nov 2010 11:37:24 -0800
From: "[redacted]" <[redacted]>
Reply-To: "[redacted]" [redacted]
To: [redacted]
Subject: Someone commented on your thing
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4cd85174328d6_1486..fdbe5b8d87fe--mimepart_4cd85174328d6_1486..fdbe5b8d87fe
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline[the content of the plain text part]
[the content of the html part]
--mimepart_4cd85174328d6_1486..fdbe5b8d87fe--
Log for the blank email:
Rendered shared/attachments/_count (0.1ms)
Rendered layouts/speech/_bubble (0.6ms)
Rendered layouts/speech/_detail (0.7ms)
Rendered notifications/_comment (1.6ms)
Rendered layouts/_footer (25.9ms)
Rendered layouts/_container (26.1ms)
Sent mail to [redacted]Date: Mon, 8 Nov 2010 11:37:29 -0800
From: "[redacted]" <[redacted]>
Reply-To: "[redacted]" <[redacted]>
To: [redacted]
Subject: Someone commented on your thing
Mime-Version: 1.0
Content-Type: multipart/alternative; charset=utf-8[the content of the HTML part]
Note that those emails were sent 5 seconds apart, and both emails (were supposed to) contain the same thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不久前,我在使用 DJ 和 ActionMailer 时遇到了这个问题 - 结果是我在两台实用程序服务器上运行 DJ,而我认为这只是一台服务器,而我的部署挂钩仅在一台服务器上重新启动了 DJ 守护进程,而在另一台服务器上则没有重新启动,这导致了整个问题诸如此类的一堆问题。
最让我头疼的是 60% 的事情——有些表现良好,而另一些则完全变形,但 DJ 守护进程在一台服务器上重置,而不是在另一台服务器上完全解释了这种不一致。
希望这有帮助!
I had this issue a while back with DJ and ActionMailer- turned out I was running DJ on two utility servers where I thought it was only one, and my deploy hook only restarted the DJ daemon on one and not the other and that caused a whole bunch of problems like this.
The thing that had my head splitting the most was the 60% thing- where some were going out fine where others were completely deformed, but the DJ daemon being reset on one server and not the other totally explained the inconsistency.
Hope this helps!