如何在Rails 2.3.11中以HTML格式发送邮件?

时间:2011-07-19 21:54:53

标签: ruby-on-rails mime-types actionmailer

到目前为止,我只找到了适用于Rails 3的解决方案。如何强制将使用ActionMailer发送的电子邮件格式化为HTML,而不是纯文本?

/app/models/franklin.rb(邮件程序)

class Franklin < ActionMailer::Base
  def activation(user)
    recipients      user.email
    from            "activation@rit.oncampusapp.net"
    content_type    = "text/html"
    subject         "OnCampus @ RIT Registration"
    body            :user => user
  end
end

/app/views/franklin/activation.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  </head>
  <body>

Hi <%= @user.full_name %>,

This is your activation email for OnCampus @ RIT.  All you have to do is click the link below, and you'll be able to log in.

<%= link_to "Activate My Account!", "http://rit.oncampusapp.net/admin/activate?key=#{@user.activation_key}"%>

We hope to see you soon! :D

-- The OnCampus Team

</body>
</html>

2 个答案:

答案 0 :(得分:3)

您是否尝试过设置激活操作 content_type“text / html”而不是 content_type =“text / html”

答案 1 :(得分:2)

只需将其粘贴到通知程序/邮件程序模型方法中 - 这将解决您的问题

content_type  "text/html"