Подтвердить что ты не робот

Как настроить почтовый перехватчик в рельсах 3.0.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)

Как это исправить?

Код, который я использую, показан ниже:

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?

Библиотека/development_mail_interceptor.rb

class DevelopmentMailInterceptor

  def self.delivering_email(message)
    message.to = "email"
  end

end

Спасибо заранее.

4b9b3361

Ответ 1

require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?

Ответ 2

Мне было проще установить драгоценный камень mailcatcher. Затем в development.rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "`localhost`",
    :port                 => 1025
  }

Затем просто запустите "mailcatcher" и нажмите http://localhost:1080/ в браузере. Он работает в фоновом режиме, но может быть удален непосредственно из браузера. Дает вам текстовые + html-представления, источник и анализ с фракталом, если вы так раскачиваетесь. Супер-чистый.