[英]Rails 4 with Devise on Heroku - Issue with sending mail
我終於在開發中正確發送了電子郵件確認(使用Devise進行身份驗證等),但是在生產中我根本無法正常工作。
更新/編輯#1:
在嘗試了以下建議(不幸的是,該建議未能解決問題)之后,我按如下所示修改了生產設置:
更新/編輯#2:
試圖修改:domain
值:
Rails.application.routes.default_url_options[:host] = 'obscure-crag-6843.herokuapp.com'
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => 'smtp.sengrid.net',
:port => 587,
:authentication => 'plain',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'obscure-crag-6843.heroku.com',
:enable_starttls_auto => true
}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
仍然出現錯誤:
2015-02-02T16:52:39.634893+00:00 app[web.1]: Processing by Devise::ConfirmationsController#create as HTML
2015-02-02T16:52:39.624339+00:00 app[web.1]: Started POST "/users/confirmation" for 66.108.200.119 at 2015-02-02 16:52:39 +0000
2015-02-02T16:52:39.634923+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"3yPKp3FqN2Mfxg+s28xQDpLhWtkLRFt1ZxfygyM5JNKCGlo1+nsx0dXy0NbSt7D80TvKIuPfSESziGQ/L9HoiQ==", "user"=>{"email"=>"groundhog.nice@gmail.com"}, "c
ommit"=>"Resend confirmation instructions"}
2015-02-02T16:52:39.673202+00:00 app[web.1]: User Load (12.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "groundhog.nice@gmail.com"]]
2015-02-02T16:52:39.673202+00:00 app[web.1]: User Load (12.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "groundhog.nice@gmail.com"]]
2015-02-02T16:52:39.928958+00:00 app[web.1]: User Load (3.5ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["confirmation_token", "d00c657be3922503cb350e6db9e5b20ac6daa2
a8aa401fb346d504d0e2d89f2e"]]
2015-02-02T16:52:39.941419+00:00 app[web.1]: SQL (3.2ms) UPDATE "users" SET "confirmation_token" = $1, "confirmation_sent_at" = $2, "updated_at" = $3 WHERE "users"."id" = $4 [["confirmation_token", "d00c657be3922503cb350e6db9e5b20ac
6daa2a8aa401fb346d504d0e2d89f2e"], ["confirmation_sent_at", "2015-02-02 16:52:39.929928"], ["updated_at", "2015-02-02 16:52:39.933892"], ["id", 1]]
2015-02-02T16:52:40.047348+00:00 app[web.1]: Rendered devise/mailer/confirmation_instructions.html.erb (7.5ms)
2015-02-02T16:52:39.933525+00:00 app[web.1]: (3.2ms) BEGIN
2015-02-02T16:52:39.949859+00:00 app[web.1]: (7.8ms) COMMIT
2015-02-02T16:52:40.300090+00:00 app[web.1]: Devise::Mailer#confirmation_instructions: processed outbound mail in 347.2ms
2015-02-02T16:52:40.300084+00:00 app[web.1]:
2015-02-02T16:53:09.608907+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/users/confirmation" host=obscure-crag-6843.herokuapp.com request_id=88102416-e8e8-4e2d-904e-61505b7cc80d fwd="66.108.200.119" d
yno=web.1 connect=2ms service=30001ms status=503 bytes=0
2015-02-02T16:53:10.591515+00:00 app[web.1]: From: please-change-me-at-config-initializers-devise@example.com
2015-02-02T16:53:10.591525+00:00 app[web.1]: Mime-Version: 1.0
2015-02-02T16:53:10.591522+00:00 app[web.1]: Message-ID: <54cfab584a63e_33f8391b77e986273@5849319e-9d85-442b-b13b-b79cd9373d33.mail>
2015-02-02T16:53:10.591526+00:00 app[web.1]: Content-Type: text/html;
2015-02-02T16:53:10.539928+00:00 app[web.1]: Sent mail to groundhog.nice@gmail.com (30239.5ms)
2015-02-02T16:53:10.591510+00:00 app[web.1]: Date: Mon, 02 Feb 2015 16:52:40 +0000
2015-02-02T16:53:10.591520+00:00 app[web.1]: To: groundhog.nice@gmail.com
2015-02-02T16:53:10.539921+00:00 app[web.1]:
2015-02-02T16:53:10.591518+00:00 app[web.1]: Reply-To: please-change-me-at-config-initializers-devise@example.com
2015-02-02T16:53:10.591532+00:00 app[web.1]: <p>Welcome groundhog.nice@gmail.com!</p>
2015-02-02T16:53:10.591528+00:00 app[web.1]: charset=UTF-8
2015-02-02T16:53:10.591523+00:00 app[web.1]: Subject: Confirmation instructions
2015-02-02T16:53:10.591528+00:00 app[web.1]: charset=UTF-8 [115/1420]
2015-02-02T16:53:10.591523+00:00 app[web.1]: Subject: Confirmation instructions
2015-02-02T16:53:10.591529+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2015-02-02T16:53:10.591912+00:00 app[web.1]: Completed 500 Internal Server Error in 30957ms
2015-02-02T16:53:10.591534+00:00 app[web.1]: <p>You can confirm your account email through the link below:</p>
2015-02-02T16:53:10.591535+00:00 app[web.1]:
2015-02-02T16:53:10.591537+00:00 app[web.1]: <p><a href="http://obscure-crag-6843.herokuapp.com/users/confirmation?confirmation_token=c9agbLB_yT57z4shtjZP">Confirm my account</a></p>
2015-02-02T16:53:10.591530+00:00 app[web.1]:
2015-02-02T16:53:10.591533+00:00 app[web.1]:
2015-02-02T16:53:10.591538+00:00 app[web.1]:
2015-02-02T16:53:10.630637+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:520:in `start'
2015-02-02T16:53:10.630628+00:00 app[web.1]: Net::OpenTimeout (execution expired):
2015-02-02T16:53:10.630630+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `initialize'
2015-02-02T16:53:10.630631+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `open'
2015-02-02T16:53:10.630633+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `tcp_socket'
2015-02-02T16:53:10.630634+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:551:in `block in do_start'
2015-02-02T16:53:10.630635+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:550:in `do_start'
2015-02-02T16:53:10.630623+00:00 app[web.1]:
2015-02-02T16:53:10.630645+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
在這一點上,我要么嘗試使用其他郵件提供商,要么暫時回到Gmail,盡管當然,我最終將不得不對此進行處理。 如果有人有其他建議,那就太好了。
我認為這是這行:
:address => 'smtp.sengrid.net',
我也無法在生產環境中發送電子郵件(設計,heroku),但我能夠解決它。 將我的代碼設置與您的代碼設置進行比較,發現以下幾行不同:
Rails.application.routes.default_url_options [:host] ='obscure-crag-6843.herokuapp.com'
:domain =>'obscure-crag-6843.heroku.com',
:address =>'smtp.sengrid.net',
在
Rails.application.configure do
我有
config.action_mailer.default_url_options = {主機:'myappname.herokuapp.com'}
和在
config.action_mailer.smtp_settings
一切都一樣,除了
:address =>'smtp.sendgrid.net',(您拼寫了sendgrid)
:domain =>'heroku.com',
當然,您需要將Sendgrid添加到Heroku。 希望這可以幫助!
我注意到您在代碼中使用了:domain屬性。 盡管我以前從未使用過,但您可以嘗試將域更改為您的app-name.heroku.com而不是heorku.com嗎? 我將向您展示如何為自己使用郵寄代碼:
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["gmail_username"],
password: ENV["gmail_password"]
}
祝好運 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.