如何在rails 3.0.3中设置邮件拦截器?

发布于 2024-11-11 12:35:55 字数 1199 浏览 3 评论 0原文

我正在使用 Rails 3.0.3、ruby 1.9.2-p180、邮件(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

提前致谢。

I am using rails 3.0.3, ruby 1.9.2-p180, mail (2.2.13). I m trying to setup a mail interceptor but I am getting the following error

 /home/abhimanyu/Aptana_Studio_3_Workspace/delivery_health_dashboard_03/config/initializers/mailer_config.rb:16:in `<top (required)>': uninitialized constant DevelopmentMailInterceptor (NameError)

How do i fix it?

The code I am using is shown below:

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

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦行僧 2024-11-18 12:35:55
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?
音盲 2024-11-18 12:35:55

我发现安装 mailcatcher gem 更容易。然后在development.rb中:

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

然后运行“mailcatcher”并在浏览器中点击http://localhost:1080/。它在后台运行,但可以直接从浏览器退出。为您提供文本+html 视图、源代码和分形分析(如果您这样做的话)。超级干净。

I found it easier to install the mailcatcher gem. Then in development.rb:

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

Then just run "mailcatcher" and hit http://localhost:1080/ in a browser. It runs in the background, but can be quit directly from the browser. Gives you text+html views, source, and analysis with fractal, if you swing that way. Super-clean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文