Mandrill raw_message中的额外"\n"打破了一些链接

Joe*_*gen 5 ruby-on-rails mandrill

我通过SMTP从Heroku的Rails应用程序发送电子邮件到Mandrill.

一切都运行良好一段时间,但最近(2天前检测到),我们收到报告称某些链接已损坏.

当我通过SMTP将消息发送到Mailtrap时,原始消息很好,HTML主体在一行中.

但是,在Mandrill上,raw_messageAPI调用中出现的内容包含extra \n(这是一个换行后跟一个空格).

运气不好,链接显示如下:

<a href=\"https://www.\n facebook.com/
Run Code Online (Sandbox Code Playgroud)

链接跟踪开启后,将转换为:

https://www.%20facebook.com/
Run Code Online (Sandbox Code Playgroud)

链接跟踪关闭,邮箱理解如下:

https://www.%0d%0a%20facebook.com/
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,链接显然都被打破了.看到SMTP消息看起来很好,我猜测Mandrill的SMTP服务器在调用API时添加换行符.我该怎么办?我怎么能成为唯一一个看似受影响的人呢?

任何帮助都很受欢迎,包括解决方法,因为这也打破了生产中的"重置密码"链接!

编辑

这是我在mailtrap中获得的(略微编辑的)原始消息.这是多部分文本/ HTML,一切看起来都不错.

Date: Thu, 26 Feb 2015 16:11:49 +0000
From: redacted <notifications+staging@redacted.com>
Reply-To: redacted <support@redacted.io>
To: redacted@redacted.com
Message-ID: <54ef45c51372b_3a3fddaa4e53f081961@3d32585e-59a2-456b-b7ff-4ed464b73400.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_54ef45c510602_3a3fddaa4e53f081842";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_54ef45c510602_3a3fddaa4e53f081842
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello redacted,

Someone has requested a link to change your password for redacted. You can do this through the link below.

http://redacted.io/security/users/password/edit?reset_password_token=redacted

If you didn't request this, please ignore this email

Your password won't change until you access the link above and create a new one.

----==_mimepart_54ef45c510602_3a3fddaa4e53f081842
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<div style="width: 100%; background: #ffffff;"><table style="width: 100%; max-width: 520px; margin: 0 auto; border: 0; border-collapse: collapse;"><tr><td style="width: 50%;  padding: 10px;"><img alt="redacted" src="https://s3-eu-west-1.amazonaws.com/redacted/redacted.png" /></td><td style="width: 50%; padding: 20px; text-align: right; vertical-align: middle; font-family: Helvetica,Arial,sans-serif; color: #8494a4; font-size: 14px;">LOST PASSWORD</td></tr><tr><td colspan="2" style="padding: 40px 50px 20px 50px; font-family: Helvetica,Arial,sans-serif; color: #8494a4; font-size: 14px;"><p>Hello redacted,</p><p>Someone has requested a link to change your password for redacted. You can do this through the link below.</p></td></tr></table><table style="width: 100%; max-width: 520px; margin: 0 auto; border: 0; border-collapse: collapse;"><tr><td width="33%"></td><td style="background: #3897d3; text-align: center; vertical-align: middle; width: 34%; height: 50px;" width="34%"><a href="http://redacted.io/security/users/password/edit?reset_password_token=redacted" style="font-family: Helvetica,Arial,sans-serif; font-size: 14px; color: #ffffff; text-decoration: none; background: #3897d3; display: block; padding: 15px 0; text-align: center;">Change password</a></td><td width="33%"></td></tr><tr><td colspan="3" style="padding: 20px 50px; font-family: Helvetica,Arial,sans-serif; color: #8494a4; font-size: 14px;"><p>If you didn&#39;t request this, please ignore this email</p><p>Your password won&#39;t change until you access the link above and create a new one.</p></td></tr><tr><td colspan="3" style="padding: 30px 0 10px 0; text-align: center; font-family: Helvetica,Arial,sans-serif; font-size: 12px; color: #8494a4;"><a href="http://redacted.io/" style="color: #3897d3; text-decoration: none;">redacted</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="https://twitter.com/redacted" style="color: #3897d3; text-decoration: none;">Twitter</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="https://www.facebook.com/redacted" style="color: #3897d3; text-decoration: none;">Facebook</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="https://plus.google.com/redacted" style="color: #3897d3; text-decoration: none;">Google+</a></td></tr></table></div>
----==_mimepart_54ef45c510602_3a3fddaa4e53f081842--
Run Code Online (Sandbox Code Playgroud)

Kai*_*lin 9

我们通常会看到生成HTML而没有真正换行符的SMTP库或框架的这种问题.SMTP规范声明电子邮件的行长度不应超过1000个字符.达到该限制时,在通过SMTP传输邮件数据时会自动插入换行符.不幸的是,这经常发生在例如单词或URL的中间.您需要查看SMTP库,看看是否可以修改换行符的处理方式.

如果你正在使用像<br>这样的HTML换行符来表示中断,那么遗憾的是,在这种情况下,这些不会有帮助.添加自己的换行符(不是HTML换行符,但数据中的实际换行符,例如换行符或行尾 - 通常\r\n会有助于确保在不方便的地方SMTP会话中不会任意添加强制换行符.