ActionMailer without Rails - views not being picked up
I've set up Act开发者_如何转开发ionMailer 3.x for use outside of Rails, but the emails don't have a body. Can anyone help?
# ./app.rb
require 'action_mailer'
ActionMailer::Base.delivery_method = :file
ActionMailer::Base.file_settings[:location] = './tmp/mails'
ActionMailer::Base.view_paths = './views'
class Mailer < ActionMailer::Base
def instructions(email_address)
mail(:to => email_address, :subject => 'hello')
end
end
Mailer.instructions('test@email.com').deliver
Then I have two files for my views, one for plain text
# ./views/mailer/instructions.text.erb
These are some instructions
And one for html (using HAML - I know there are some potential issues with this, any advice here would be appreciated too!)
# ./views/mailer/instructions.html.haml
%html
%body
%h1 These are some HTML instructions
But if I check my newly created ./tmp/mails/test@email.com
I only have the following, and no body text:
Date: Wed, 07 Sep 2011 18:38:09 +0530
From: my@address.com
To: test@email.com
Message-ID: <4e676ab8e2bc5_274560aab8567d0@mycomputer.mail>
Subject: hello
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Any ideas what's going on here? Thanks in advance
After migration from Rails 2.x -> 3.x I had the same problem (a bit different setup though). My html emails had no body. I moved my mailer class from models folder into mailers folder and changed my view file names:
file_name.text.html.erb
=>
file_name.html.erb
I hope this helps.
精彩评论