【问题标题】:Sending an email from Rails app- works in development, not in production on Heroku从 Rails 应用程序发送电子邮件——在 Heroku 上的开发中,而不是在生产中
【发布时间】:2012-08-17 17:43:18
【问题描述】:

我正在尝试使用 gem Active Admin 向我注册的用户发送电子邮件,以便他们可以创建密码。

这需要在 config/environments/development.rb 中插入以下代码

 #Added per active admin install instructions
 config.action_mailer.default_url_options = { :host => 'localhost:3000' }

 #These settings are for the sending out email for active admin and consequently the devise mailer
 ActionMailer::Base.delivery_method = :smtp
 ActionMailer::Base.perform_deliveries = true
 ActionMailer::Base.raise_delivery_errors = true
 ActionMailer::Base.smtp_settings = 
 {

   :address            => 'smtp.gmail.com',
   :port               => 587,
   :domain             => 'gmail.com', #you can also use google.com
   :authentication     => :plain,
   :user_name          => 'XXX@gmail.com',
   :password           => 'XXXX'
 }

这没问题

用于部署到 Heroku 上的生产站点。我将以下代码插入到 config/environments/production.rb

 #Added per active admin install instructions
 config.action_mailer.default_url_options = { :host => 'http://XXXX.herokuapp.com/' }

 #These settings are for the sending out email for active admin and consequently the devise mailer
 ActionMailer::Base.delivery_method = :smtp
 ActionMailer::Base.perform_deliveries = true
 ActionMailer::Base.raise_delivery_errors = true
 ActionMailer::Base.smtp_settings = 
 {

   :address            => 'smtp.gmail.com',
   :port               => 587,
   :domain             => 'gmail.com', #you can also use google.com
   :authentication     => :plain,
   :user_name          => 'XXX@gmail.com',
   :password           => 'XXX'
 }

但是现在电子邮件没有发送出去。相反,我在浏览器中看到“我们很抱歉出现错误”消息,并且日志显示以下几行

2012-08-17T17:39:34+00:00 app[web.1]:     cache: [GET /admin/admin_users/new] miss

2012-08-17T17:39:34+00:00 app[web.1]: Started POST "/admin/admin_users" for   96.49.201.234 at 2012-08-17 17:39:34 +0000
2012-08-17T17:39:35+00:00 app[web.1]: Net::SMTPAuthenticationError (535-5.7.1 Please log   in with your web browser and then try again. Learn more at

2012-08-17T17:39:35+00:00 app[web.1]: ):
2012-08-17T17:39:35+00:00 app[web.1]:   app/models/admin_user.rb:35:in `block in <class:AdminUser>'

2012-08-17T17:39:35+00:00 app[web.1]: cache: [POST /admin/admin_users] invalidate, pass

我应该从这里去哪里?谁能帮帮我

【问题讨论】:

    标签: ruby-on-rails heroku devise actionmailer activeadmin


    【解决方案1】:

    这是来自 Gmail 的有用帮助:http://support.google.com/mail/bin/answer.py?hl=en&answer=14257&p=client_login

    问题在于 Gmail 阻止了可能是机器人的可疑登录尝试。我们需要向该应用授予权限,以便它可以使用 Google 帐户发送电子邮件。

    【讨论】:

      【解决方案2】:

      Gmail 需要 SSL 连接到他们的邮件服务器。尝试将此添加到您的 SMTP 设置中:

      :enable_starttls_auto => true
      

      【讨论】:

        【解决方案3】:

        试试下面的代码:

         ActionMailer::Base.smtp_settings = 
         {
        
           :address              => 'smtp.gmail.com',
           :port                 => 587,
           :domain               => 'gmail.com', #you can also use google.com
           :authentication       => 'plain',
           :user_name            => 'XXX@gmail.com',
           :password             => 'XXX',
           :enable_starttls_auto => true
         }
        

        所做的更改:
        1. :authentication =&gt; :action:authentication =&gt; 'plain'
        2. 添加:enable_starttls_auto =&gt; true,正如上面janders223评论的那样。

        【讨论】:

          【解决方案4】:

          http://www.google.com/accounts/DisplayUnlockCaptcha 点击它并授予访问权限。下一次就可以了

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-12-12
            • 2013-12-09
            • 1970-01-01
            • 1970-01-01
            • 2014-10-01
            • 1970-01-01
            相关资源
            最近更新 更多