Rails 邮件程序和链接在 Thunderbird 下不起作用

发布于 2024-11-30 00:39:18 字数 2665 浏览 1 评论 0原文

我想用我的 Rails Mailer 发送 html 电子邮件。 可以是multipart/alternative或只是text/html。 问题是,当我发送带有链接的电子邮件时,它在 Gmail 上显示得很好,但在 Thunderbird 中则不太好。

问题是,在 Thunderbird 中,该链接“不可点击”——它像链接一样突出显示,但点击它不会执行任何操作。

其他邮件(不是从 Rails Mailer 发送)上的链接可以完美运行。

所以我的问题是:如何正确发送 html 电子邮件,以便正确查看?

邮件程序代码:

class MyMailer < ActionMailer::Base
  def mailing_delivery(email, subject)
    mail(:to => email, :subject => subject)
  end

邮件视图:

# mailing_delivery.html.haml 
%p
  Thanks! Its your mailer!
%p
  = link_to "Google", "google.com"

电子邮件来源 (某些部分被剪掉)

Date: Thu, 18 Aug 2011 14:32:34 +0200
From: xxx
To: xxx
Message-ID: <[email protected]>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
X-O2-Trust: 2, 64
X-O2-SPF: neutral

<p>
  Thanks! It's your mailer!
</p>
<p>
  <a href="google.com">Google</a>
</p>

当然Rails 3. Thunderbird 5.0,但这不是问题 - 因为不知何故其他邮件显示良好..而且我不认为它是特定于应用程序的。

我应该怎么做才能使这项工作成功?

编辑:我尝试通过执行 mail(:to => email, :subject => subject, "Content- Transfer-Encoding" => value) 或类 default "Content-Transfer-Encoding" => value 没有运气..如何改变它?

在 Thunderbird 下运行良好的电子邮件具有 Content-Transfer-Encoding: Quoted-printable (或最终 base64),所以也许这就是问题所在?我该如何改变它?

编辑2:我设法将Content-Transfer-Encoding更改为quoted-printable,但它正在剪切内容,如下所示:

Date: Thu, 18 Aug 2011 22:04:21 +0200
From: xxx
To: xxx
Message-ID: <[email protected]>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-O2-Trust: 2, 63
X-O2-SPF: neutral

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww=
w.w3.org/TR/html4/loose.dtd">
<html>
  <body>
    <p>
      Thanks! It's your mailer!
    </p>
    <p>
      <a href=

另一件事:为什么 Content-Type 中有一个换行符?我在其他(工作良好)邮件中没有看到它。我怎样才能摆脱它?

I want to send html email's with my Rails Mailer.
Could be multipart/alternative or only text/html.
Problem is, when I send an email with a link, it appears well on Gmail, but not so good in Thunderbird.

The problem is, that in Thunderbird, the link is 'not clickable' - it's highlighted like a link, but clicking on it does nothing.

Links on other mails (not sent from Rails Mailer) work flawlessly.

So my question is: how to properly send an html email, so it will be viewed properly?

Mailer code:

class MyMailer < ActionMailer::Base
  def mailing_delivery(email, subject)
    mail(:to => email, :subject => subject)
  end

Mail view:

# mailing_delivery.html.haml 
%p
  Thanks! Its your mailer!
%p
  = link_to "Google", "google.com"

Source of email (some parts cut-out):

Date: Thu, 18 Aug 2011 14:32:34 +0200
From: xxx
To: xxx
Message-ID: <[email protected]>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
X-O2-Trust: 2, 64
X-O2-SPF: neutral

<p>
  Thanks! It's your mailer!
</p>
<p>
  <a href="google.com">Google</a>
</p>

Of course Rails 3. Thunderbird 5.0, but that's not the issue - because somehow other mails show up good.. And I don't think it's app specific.

What should I do, to make this work?

Edit: I tried to change the 'content-transfer-encoding' header with no success, by doing mail(:to => email, :subject => subject, "Content-Transfer-Encoding" => value) or in class default "Content-Transfer-Encoding" => value with no luck.. how to change that?

Emails that works good under Thunderbird have Content-Transfer-Encoding: quoted-printable (or eventually base64) so maybe that's the issue? How do I change it?

Edit 2: I managed to change the Content-Transfer-Encoding to quoted-printable but it's cutting the content, like this:

Date: Thu, 18 Aug 2011 22:04:21 +0200
From: xxx
To: xxx
Message-ID: <[email protected]>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-O2-Trust: 2, 63
X-O2-SPF: neutral

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww=
w.w3.org/TR/html4/loose.dtd">
<html>
  <body>
    <p>
      Thanks! It's your mailer!
    </p>
    <p>
      <a href=

One other thing: why is there a newline in Content-Type ? I didn't see it in other (working good) mails. How I can get rid of it?

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

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

发布评论

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

评论(1

野却迷人 2024-12-07 00:39:18

如果你修复你的 html 也许它会起作用。因此,不要只是拥有:

<p>
  Thanks! It's your mailer!
</p>
<p>
  <a href="google.com">Google</a>
</p>

尝试:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <body>
    <p>
      Thanks! It's your mailer!
    </p>
    <p>
      <a href="http://google.com">Google</a>
    </p>
  </body>
</html>

Maybe it'll work if you fix your html. So instead of just having:

<p>
  Thanks! It's your mailer!
</p>
<p>
  <a href="google.com">Google</a>
</p>

try:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <body>
    <p>
      Thanks! It's your mailer!
    </p>
    <p>
      <a href="http://google.com">Google</a>
    </p>
  </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文