用户确认电子邮件不发送到生产中。 Rails,Heroku,Gmail
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用户确认电子邮件不发送到生产中。 Rails,Heroku,Gmail相关的知识,希望对你有一定的参考价值。
我已经遍布谷歌和stackoverflow寻找答案,但一直无法找到任何解决方案。我正在尝试设置smtp电子邮件,以便在注册后进行用户确认。它在开发中工作正常。即使使用MailCatcher,它也会以某种方式绕过它并从我指定的Gmail发送到正确的电子邮件。
config.action_mailer.raise_deliver_errors = true
config.action_mailer.perform_deliveries = true
config.assets.raise_runtime_errors = false
config.assets.quiet = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:enable_starttls_auto => true,
:domain => 'hieu-vo.herokuapp.com',
:port => 587 ,
:user_name => 'xxxxx@gmail.com',
:password => 'xxxxxx',
:authentication => 'plain',
:openssl_verify_mode => 'none' }
config.action_mailer.default_url_options = { host: 'hieu-vo.herokuapp.com' }
这是我使用heroku logs --tail
时的日志
2018-09-11T16:23:35.044137+00:00 app[web.1]: I, [2018-09-11T16:23:35.043151 #4] INFO -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Started POST "/users" for 113.188.247.92 at 2018-09-11 16:23:35 +0000
2018-09-11T16:23:35.045638+00:00 app[web.1]: I, [2018-09-11T16:23:35.045531 #4] INFO -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Processing by UsersController#create as html
2018-09-11T16:23:35.045793+00:00 app[web.1]: I, [2018-09-11T16:23:35.045709 #4] INFO -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Parameters: {"utf8"=>"✓", "authenticity_token"=>"cJWQmMOh4zUFre1fps03tYuYbbyA8ykZZF3djpwUpe8KWfabD5PUA8ZaC4VQ8VmF9nGVNrxUOomPCRpsKJk7aQ==", "user"=>{"email"=>"mailtest@test.com", "name"=>"hello"}, "commit"=>"Send to me"}
2018-09-11T16:23:35.050036+00:00 app[web.1]: D, [2018-09-11T16:23:35.049890 #4] DEBUG -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] (0.6ms) BEGIN
2018-09-11T16:23:35.055921+00:00 app[web.1]: D, [2018-09-11T16:23:35.055783 #4] DEBUG -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] SQL (3.4ms) INSERT INTO "users" ("name", "email", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["name", "hello"], ["email", "mailtest@test.com"], ["created_at", "2018-09-11 16:23:35.050372"], ["updated_at", "2018-09-11 16:23:35.050372"]]
2018-09-11T16:23:35.059314+00:00 app[web.1]: D, [2018-09-11T16:23:35.059167 #4] DEBUG -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] (2.6ms) COMMIT
2018-09-11T16:23:35.520783+00:00 heroku[router]: at=info method=POST path="/users" host=hieu-vo.herokuapp.com request_id=1b2a2e36-58d4-4845-acfd-2b6fa1621d55 fwd="113.188.247.92" dyno=web.1 connect=1ms service=495ms status=500 bytes=1827 protocol=https
2018-09-11T16:23:35.508523+00:00 app[web.1]: D, [2018-09-11T16:23:35.508354 #4] DEBUG -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] UserMailer#registration_confirmation: processed outbound mail in 447.9ms
2018-09-11T16:23:35.517607+00:00 app[web.1]: I, [2018-09-11T16:23:35.517469 #4] INFO -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Sent mail to nhokkonkk13@gmail.com (8.8ms)
2018-09-11T16:23:35.517699+00:00 app[web.1]: D, [2018-09-11T16:23:35.517609 #4] DEBUG -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Date: Tue, 11 Sep 2018 16:23:35 +0000
2018-09-11T16:23:35.517702+00:00 app[web.1]: From: from@example.com
2018-09-11T16:23:35.517704+00:00 app[web.1]: To: nhokkonkk13@gmail.com
2018-09-11T16:23:35.517706+00:00 app[web.1]: Message-ID: <5b97ec077d6b2_411cabc85239@ba563531-54e7-4e4c-8f59-50279af29818.mail>
2018-09-11T16:23:35.517708+00:00 app[web.1]: Subject: [MAILTO HIEUVO] SOMEONE VISIT YOUR WEBSITE!!!
2018-09-11T16:23:35.517710+00:00 app[web.1]: Mime-Version: 1.0
2018-09-11T16:23:35.517711+00:00 app[web.1]: Content-Type: text/plain;
2018-09-11T16:23:35.517713+00:00 app[web.1]: charset=UTF-8
2018-09-11T16:23:35.517715+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2018-09-11T16:23:35.517716+00:00 app[web.1]:
2018-09-11T16:23:35.517718+00:00 app[web.1]: !!!!!!mailtest@test.com TALK TO YOU: hello
2018-09-11T16:23:35.518083+00:00 app[web.1]: I, [2018-09-11T16:23:35.517991 #4] INFO -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Completed 500 Internal Server Error in 472ms (ActiveRecord: 6.6ms)
2018-09-11T16:23:35.519035+00:00 app[web.1]: F, [2018-09-11T16:23:35.518945 #4] FATAL -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55]
2018-09-11T16:23:35.519131+00:00 app[web.1]: F, [2018-09-11T16:23:35.519042 #4] FATAL -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
2018-09-11T16:23:35.519216+00:00 app[web.1]: F, [2018-09-11T16:23:35.519135 #4] FATAL -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55]
2018-09-11T16:23:35.519334+00:00 app[web.1]: F, [2018-09-11T16:23:35.519255 #4] FATAL -- : [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] app/controllers/users_controller.rb:40:in `block in create'
2018-09-11T16:23:35.519337+00:00 app[web.1]: [1b2a2e36-58d4-4845-acfd-2b6fa1621d55] app/controllers/users_controller.rb:38:in `create'
2018-09-11T16:23:35.932275+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=hieu-vo.herokuapp.com request_id=f7d117e3-a805-41b3-b315-524ce64899c2 fwd="113.188.247.92" dyno=web.1 connect=4ms service=9ms status=200 bytes=143 protocol=https
我想知道我的配置是否错误,但在我的本地机器上它仍然可以正常工作。因此它可能是heroku的用户问题。多谢!
答案
查看此youtube视频youtube.com/watch?v=INPqBOerfTw&t=63s
我更喜欢使用mandrill app而不是gmail https://mandrillapp.com/login/?referrer=%2F
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:domain => 'www.xyz.com',
:user_name => 'xyz',
:password => 'xxx',
:authentication => :plain,
:enable_starttls_auto => true
}
以上是关于用户确认电子邮件不发送到生产中。 Rails,Heroku,Gmail的主要内容,如果未能解决你的问题,请参考以下文章
通过电子邮件发送ActionMailer中的当前用户 - Rails 5
Rails 中的电子邮件确认,无需使用任何现有的身份验证 gem/插件
我们可以在 rails 3.0 中使用 mailchimp 发送用户通知电子邮件吗