在我的一个rails应用程序中,我必须发送一封电子邮件。我只是配置我的应用程序如下。在轨道上使用红宝石发送邮件
我正在使用Rails v2.0。
environment.rb中:
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.action_controller.session = {
:session_key => '_mailtest_session',
:secret => 'key_here'
}
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 25,
:domain => "gmail.com",
:authentication => :login,
:user_name => "[email protected]",
:password => "password"
}
ActionMailer::Base.default_content_type = "text/html"
end
型号/ notifier.rb:
class Notifier < ActionMailer::Base
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = '[email protected]'
@sent_on = sent_at
@body["title"] = 'Signup Info'
@body["email"] = '[email protected]'
@body["message"] = message
@headers = {}
return true
end
end
控制器/管理员
class AdministratorController < ApplicationController
def index
recipient = "[email protected]"
subject = "Subject"
message = "message"
Notifier.deliver_contact(recipient, subject, message)
end
end
当我试图调用索引方法我米得到这个错误:
Couldn't find template file for notifier/contact in ["D:/Rails/rails_apps/mailtest/app/views"]
请帮助...
你在那个视图目录下有什么文件? – rkb 2011-12-28 06:52:13
为了测试,我刚在我的视图文件夹中创建了一个空白的contact.html.erb文件 – ramesh 2011-12-28 08:43:31