Как настроить перехватчик почты в рельсах 3.0.3? - PullRequest
24 голосов
/ 01 июня 2011

Я использую рельсы 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

Заранее спасибо.

Ответы [ 2 ]

49 голосов
/ 01 июня 2011
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?
5 голосов
/ 08 февраля 2013

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

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

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

...