1

我正在尝试使用 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

我应该从这里去哪里?有人可以帮我一把吗

4

4 回答 4

1

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

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

于 2013-02-26T04:18:46.173 回答
0

试试下面的代码:

 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 => :action:authentication => 'plain'
2. 已添加:enable_starttls_auto => true,如上面 janders223 所述。

于 2012-10-10T14:26:02.873 回答
0

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

:enable_starttls_auto => true
于 2012-08-17T20:10:27.840 回答
0

http://www.google.com/accounts/DisplayUnlockCaptcha单击此并授予访问权限。下次它会工作

于 2017-06-29T12:58:52.510 回答