2017-11-18 141 views
0

我一直有這個問題,因爲faaarrrrr太久了。我已經看過類似於我的無數問題,似乎無法讓他們工作。Heroku設置SendGrid麻煩

我一直在使用cloud9 ide,並推送到heroku試圖發送一個簡單的電子郵件使用SendGrid。我很確定問題出在了production.rb的設置中,或者是我用SendGrid設置heroku的方式,但我只是在我的智慧結尾。

config.action_mailer.default_url_options = { :host => 'http://tranquil-plateau-41839.herokuapp.com' } 

我把它放在環境文件夾中的production.rb文件中。

UserMailer.welcome_email(@user).deliver_now 

這是坐在我的user.rb文件中的一個if語句,如果用戶保存執行。我嘗試了一百萬種不同的組合來實現這一目標,而且似乎並不想要。

這是我從Heroku的獲得-logs

2017-11-18T04:40:06.396183+00:00 app[web.1]: (2.1ms) COMMIT 
2017-11-18T04:40:06.396635+00:00 app[web.1]: Completed 302 Found in 140ms (ActiveRecord: 37.3ms) 
2017-11-18T04:40:06.396468+00:00 app[web.1]: Redirected to http://tranquil-plateau-41839.herokuapp.com/login 
2017-11-18T04:40:06.459084+00:00 app[web.1]: Started GET "/login" for 173.28.213.164 at 2017-11-18 04:40:06 +0000 
2017-11-18T04:40:06.460969+00:00 app[web.1]: Processing by SessionsController#new as HTML 
2017-11-18T04:40:06.462953+00:00 app[web.1]: Rendered sessions/new.html.haml within layouts/application (1.1ms) 
2017-11-18T04:40:06.464328+00:00 app[web.1]: Completed 200 OK in 3ms (Views: 2.7ms | ActiveRecord: 0.0ms) 
2017-11-18T04:40:06.465391+00:00 heroku[router]: at=info method=GET path="/login" host=tranquil-plateau-41839.herokuapp.com request_id=e079f0c1-4408-4c29-b4a0-0707004e02fc fwd="173.28.213.164" dyno=web.1 connect=0ms service=10ms status=200 bytes=2823 protocol=http 
2017-11-18T04:40:06.397638+00:00 heroku[router]: at=info method=POST path="/users" host=tranquil-plateau-41839.herokuapp.com request_id=f851ddf6-d55a-43b9-9631-a17e98fa47a4 fwd="173.28.213.164" dyno=web.1 connect=0ms service=147ms status=302 bytes=1064 protocol=http 

這似乎並沒有被給予的錯誤,當我看着我的SendGrid網站它不具有任何活動都不要求或反彈。所以我認爲我的配置有問題。

任何幫助將不勝感激我失去了我的想法。

******更新*******

這是我現在的production.rb文件

config.action_mailer.default_url_options = { host: "http://tranquil-plateau- 
    41839.herokuapp.com" } 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.default :charset => "utf-8" 
    config.force_ssl = true 
    config.action_mailer.smtp_settings = { 
    :address => 'smtp.sendgrid.net', 
    :port => 587, 
    :domain => 'heroku.com', 
    :user_name => 'app***@heroku.com', 
    :password => 'secret', 
    :authentication => :plain, 
    :enable_starttls_auto => true 
    } 

這是我development.rb文件

config.action_mailer.delivery_method = :smtp 
config.action_mailer.default_url_options = { host:'localhost', port: '3000'} 
config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = true 
config.action_mailer.default :charset => "utf-8" 
config.action_mailer.smtp_settings = { 
    :address => "smtp.sendgrid.net", 
    :port => 2525, 
    :domain => 'localhost:3000', 
    :user_name => 'app****@heroku.com', 
    :password => 'secret', 
    :authentication => :plain, 
    :enable_starttls_auto => true 
} 

我有一種強烈的感覺,那就是我的領域或端口是生產中的問題。但是,在開發過程中,電子郵件會成功通過。我試過一百萬種不同的變化,我似乎無法弄清楚。

+0

如果需要更多信息,請告訴我,我會爲您解決。 – Stockster

+0

'user_name'和'password'應該是你的Sendgrid用戶名和密碼。您還應該將它們設置爲環境變量而不是硬編碼它們,因爲除非您的存儲庫是私人的,否則他們將可以被其他人查看。 如果你沒有收到錯誤消息可能沒有被髮送,所以我會檢查你的user.rb文件。 – domi91c

+0

我的問題是我可以在開發環境中發送電子郵件,但是當我推送到heroku時,它不會發送。我知道或至少高度懷疑這是與域名/端口信息有關,但無法爲我的生活弄清楚。 – Stockster

回答

0

我其實自己想清楚了。問題是Heroku不喜歡被推動分支,所以它一直都是正確的。

我最終不得不與主人合併,並推動主人heroku使其工作。

有許多方法可以將分支推送到heroku,但是我很難讓它工作,即使指定了我想推送並運行分支。

我希望這可以節省一些人在未來的時間。