Abh*_*nyu 24 ruby actionmailer ruby-on-rails-3
我使用的是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)
Run Code Online (Sandbox Code Playgroud)
我如何解决它?
我使用的代码如下所示:
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
Run Code Online (Sandbox Code Playgroud)
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
Run Code Online (Sandbox Code Playgroud)
LIB /为development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.to = "email"
end
end
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Zab*_*bba 49
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
Run Code Online (Sandbox Code Playgroud)
我发现安装mailcatcher gem更容易.然后在development.rb中:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "`localhost`",
:port => 1025
}
Run Code Online (Sandbox Code Playgroud)
然后运行"mailcatcher"并点击http://localhost:1080/浏览器.它在后台运行,但可以直接从浏览器退出.如果你以这种方式摆动,给你带有分形的文本+ html视图,源和分析.超级干净.
| 归档时间: |
|
| 查看次数: |
6427 次 |
| 最近记录: |