【问题标题】:Sending an html attachment with ActionMailer 3使用 ActionMailer 3 发送 html 附件
【发布时间】:2011-07-03 05:16:00
【问题描述】:

我正在尝试发送一封包含单个 HTML 附件的电子邮件。问题是附件 html 出现在电子邮件正文中,并且视图显示为附件。和我预想的差不多。

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

class Notifier < ActionMailer::Base
  default :from => "from@example.com"

  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 实际显示在电子邮件正文中)

【问题讨论】:

    标签: ruby-on-rails attachment actionmailer


    【解决方案1】:

    这是许多电子邮件客户端的一项功能,如果他们可以内联显示附件,他们就会这样做,因此用户不必打开单独的程序来查看里面的内容。老实说,虽然它更适用于图像。

    如果您想发送一个 html 文件,您需要将它添加到一个 zip 文件或其他存档中,然后再发送。

    【讨论】:

    • 感谢您的信息。我仍然想知道为什么显示附件并且视图作为没有文件名的 HTML 附件发送。有什么不对劲。通过这个基于 Web 的邮件客户端,我可以附加一个 html 文件,它可以按预期工作。我认为我在 actionmailer 上做错了什么。
    猜你喜欢
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多