【问题标题】:exception_notification: smtp not working异常通知:smtp 不工作
【发布时间】:2012-12-13 16:52:12
【问题描述】:

我正在使用 Rails 3.2.5 和 exception_notification gem。在生产模式下,我通常使用 PostMarkApp 的 postmark-rails gem 发送电子邮件。

最初,我从 exception_notification gem 中得到一个查看错误,说明

ActionView::Template::Error (code converter not found (UTF-8 to UTF-16))

所以基于exception_notification gem raises ActionView::Template::Error (code converter not found (UTF-8 to UTF-16)) only on Heroku production mode,我搬到了

gem 'exception_notification', git: 'git://github.com/alanjds/exception_notification.git'

这解决了这个错误。现在,我希望 gem 从我的 gmail 帐户发送电子邮件,而不是使用 PostMarkApp 积分,因此我将以下内容添加到我的 production.rb 中,但异常通知尝试仅从 Post Mark App 发送电子邮件。为什么这个设置不起作用?

config.middleware.use ExceptionNotifier,
    sender_address: 'noreply@mydomain.com',
    exception_recipients: 'myemail@mydomain.com',
    sections: %w{current_user} + ExceptionNotifier::Notifier.default_sections,
    ignore_crawlers: %w{Googlebot bingbot},
    email_format: true,
    normalize_subject: true,
    smtp_settings: {
        :address              => "smtp.gmail.com",
        :port                 => "587",
        :domain               => "www.gmail.com",
        :user_name            => "myemail@gmail.com",
        :password             => "mypassword",
        :authentication       => "plain",
        :enable_starttls_auto => true,
        :openssl_verify_mode  => 'none'        
      }

config.action_mailer.delivery_method   = :postmark
config.action_mailer.postmark_settings = { :api_key => "_____" }

【问题讨论】:

    标签: smtp ruby-on-rails-3.2 postmark exception-notification


    【解决方案1】:
    【解决方案2】:

    由于某种原因,SMTP 传送似乎在开发环境中不起作用。我尝试了许多不同的设置,但始终无法使其正常工作。但是,它确实可以在我的其他环境中使用。较早的帖子似乎也表明了这一点:

    在开发中,我在 development.rb 中使用以下内容:

    config.action_mailer.delivery_method = :letter_opener
    config.middleware.use ExceptionNotifier,
      :sender_address => 'test@test.com',
      :exception_recipients => 'recipient@test.com'
    

    在我的“暂存”环境中,我在 staging.rb 中使用以下内容:

    config.action_mailer.delivery_method = :smtp
    config.middleware.use ExceptionNotifier,
      :sender_address => 'test@test.com',
      :exception_recipients => 'recipient@test.com'
    

    staging.rb 从初始化程序获取它的 SMTP 设置,我使用 SendGrid 进行 SMTP:

    ActionMailer::Base.smtp_settings = {
      :address              => "smtp.sendgrid.net",
      :port                 => 25,
      :domain               => "test.com",
      :user_name            => "user_name",
      :password             => "password",
      :authentication       => "plain"
    }
    

    【讨论】:

    • 我会使用 gem letter_opener 来查看开发中的错误邮件
    猜你喜欢
    • 2015-06-03
    • 2021-05-20
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    相关资源
    最近更新 更多