使用 ActionMailer 3 发送 html 附件

发布于 2024-11-07 08:11:45 字数 796 浏览 1 评论 0原文

我正在尝试发送一封包含单个 HTML 附件的电子邮件。问题是附件 html 出现在电子邮件正文中,而视图显示为附件。与我的预期几乎相反。

我能够正确发送其他类型的附件,但是当尝试发送单个 HTML 附件时,它始终显示而不是“附加”。

class Notifier < ActionMailer::Base
  default :from => "[email protected]"

  def welcome(email)
    attachments['this is an html file.html'] = "<b>yeah this is html!</b>"
    mail(:to => email, :subject => "Attempting an attachment")
  end
end

我的 app/views/notifier/welcome.html.erb

Hi there! This is <b>html</b> within a view

生成的电子邮件如下所示:(

注意附件 html 实际上显示在电子邮件正文中) 我的图片

I am trying to send an email which contains a single HTML attachment. The problem is that the attachment html is appearing in the body of the email, and the view is showing up as the attachment. Pretty much the opposite of what I expected.

I am able to send attachments of other types properly, but when trying to send a single attachment that is HTML, it consistently is displayed rather than 'attached'.

class Notifier < ActionMailer::Base
  default :from => "[email protected]"

  def welcome(email)
    attachments['this is an html file.html'] = "<b>yeah this is html!</b>"
    mail(:to => email, :subject => "Attempting an attachment")
  end
end

And my app/views/notifier/welcome.html.erb

Hi there! This is <b>html</b> within a view

The resulting email looks like this:

(notice the attachment html is actually displayed in the body of the email)
my image

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

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

发布评论

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

评论(1

青柠芒果 2024-11-14 08:11:45

这是许多电子邮件客户端的一个功能,如果它们可以内嵌显示附件,那么用户就不必打开单独的程序来查看里面的内容。老实说,虽然它更适合图像。

如果您想发送 html 文件,则需要将其添加到 zip 或其他存档中并发送。

This is a feature of many email clients that if they can display attachments inline they will, so the user doesn't have to open a separate program just to see what's inside. To be honest though it's more meant for images.

If you want to send an html file, you're going to need to add it to a zip or other archive and send that instead.

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