我使用的是rails 3.0.3,ruby 1.9.2-p180,mail(2.2.13)。我试图设置邮件拦截器,但我收到以下错误
/home/abhimanyu/Aptana_Studio_3_Workspace/delivery_health_dashboard_03/config/initializers/mailer_config.rb:16:in `<top (required)>': uninitialized constant DevelopmentMailInterceptor (NameError)
我该如何解决?
我使用的代码如下所示:
config/initializer/mailer_config.rb
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "secure.emailsrvr.com",
:port => '25',
:domain => "domain",
:user_name => "user_name",
:password => "password",
:authentication => :plain
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
LIB /为development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.to = "email"
end
end
提前致谢。
答案 0 :(得分:49)
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
答案 1 :(得分:5)
我发现安装mailcatcher gem更容易。然后在development.rb中:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "`localhost`",
:port => 1025
}
然后只需运行“mailcatcher”并在浏览器中点击http://localhost:1080/
即可。它在后台运行,但可以直接从浏览器退出。如果你以这种方式摆动,给你带有分形的文本+ html视图,源和分析。超清洁。