2012-08-17 37 views
1

我想使用gem Active Admin向我註冊的用戶發送電子郵件,以便他們可以創建密碼。從Rails應用程序發送電子郵件在開發中,而不是在Heroku上生產

這需要插入的配置/環境/ 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   => '[email protected]', 
    :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   => '[email protected]', 
    :password   => 'XXX' 
} 

但是現在電子郵件無法發送。相反,我看到了在瀏覽器中「抱歉soemthing出錯」消息和日誌說以下行

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 

哪裏應該何去何從?有人可以請我幫忙嗎

回答

0

Gmail需要SSL連接到他們的郵件服務器。嘗試添加這對您的SMTP設置:

:enable_starttls_auto => true 
0

嘗試下面的代碼:

ActionMailer::Base.smtp_settings = 
{ 

    :address    => 'smtp.gmail.com', 
    :port     => 587, 
    :domain    => 'gmail.com', #you can also use google.com 
    :authentication  => 'plain', 
    :user_name   => '[email protected]', 
    :password    => 'XXX', 
    :enable_starttls_auto => true 
} 

所做的更改:
1. :authentication => :action:authentication => 'plain'
2.添加:enable_starttls_auto => true,由janders223上述評論。

相關問題