我有一个邮件程序,我可以在我的日志中看到它正在发送,但电子邮件正文不包含邮件程序 View 中的任何内容。
这是因为我已经将东西放在子文件夹中并且我已经尝试使用 :template_path
在我的 mail
功能,但无济于事。
应用程序/邮件/营销/marketing_mailer.rb
class Marketing::MarketingMailer < ActionMailer::Base
require 'mail'
address = Mail::Address.new "test@example.com" # ex: "john@example.com"
address.display_name = "Text" # ex: "John Doe"
# Set the From or Reply-To header to the following:
address.format # returns "John Doe <john@example.com>"
default from: address
# Sends an email when someone fills out the contact form
def contact(name, email, message)
@name = name
@email = email
@message = message
mail(:subject => "Test", :to => 'test@example.com', :reply_to => @email) # <== I've tried using :template_path => 'marketing', 'marketing/marketing_mailer', etc, but none worked.
end
end
/app/views/marketing/marketing_mailer/contact.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>Name: <%= @name %></p>
<p>Email: <%= @email %></p>
<p>Message: <%= @message %></p>
</body>
</html>
我注意到 devise 在/views/devise/mailers/... 中有邮件 View ,所以我知道这是可能的,但我不确定如何。
最佳答案
您是否尝试过使用 {:template_path => 'marketing/marketing_mailer, :template_name =>'contact'} 发送邮件?
模板名称可能以某种方式期望文件名中的命名空间
关于ruby-on-rails - 子文件夹中的 Rails 邮件程序和邮件程序 View 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20343882/