RoR 使用 html 模板发送电子邮件
RoR send email with html template
我想用 html.erb 模板发送电子邮件,我有一些代码。
像这样:
class Mailer < ActionMailer::Base
def notification(to_email)
begin
mail(to: 'test@oooooo.com', subject: "Test message")
rescue Exception => e
return
end
end
end
还有一些html.erb文件:
Hello, <%= @name %>.
但我不知道如何为我的方法附加此模板。
请帮我解决这个问题,因为我通常无法找到有关它的手册。
您可以在 app/views/mailer
目录中创建一个名为 notification.html.erb
的页面。您将获得在 def notification(to_email)
中定义的 notification.html.erb
中的所有实例变量
def notification(to_email)
@name = #pass name here
#your code goes here
end
现在 @name
将在 notification.html.erb
中可用
Hello, <%= @name %>
我想用 html.erb 模板发送电子邮件,我有一些代码。 像这样:
class Mailer < ActionMailer::Base
def notification(to_email)
begin
mail(to: 'test@oooooo.com', subject: "Test message")
rescue Exception => e
return
end
end
end
还有一些html.erb文件:
Hello, <%= @name %>.
但我不知道如何为我的方法附加此模板。 请帮我解决这个问题,因为我通常无法找到有关它的手册。
您可以在 app/views/mailer
目录中创建一个名为 notification.html.erb
的页面。您将获得在 def notification(to_email)
notification.html.erb
中的所有实例变量
def notification(to_email)
@name = #pass name here
#your code goes here
end
现在 @name
将在 notification.html.erb
中可用
Hello, <%= @name %>