用于用户确认的电子邮件未在生产中发送。 Rails,Heroku,Gmail

时间:2018-09-11 16:34:29

标签: ruby-on-rails email heroku configuration gmail

我已经在Google和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的用户问题。 非常感谢!

1 个答案:

答案 0 :(得分:1)

查看此youtube视频youtube.com/watch?v=INPqBOerfTw&t=63s

我更喜欢使用mandrill应用而不是gmail https://mandrillapp.com/login/?referrer=%2F

Refused to load the image 'https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d' 
because it violates the following Content Security Policy directive:
"img-src 'self' data: assets-cdn.github.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com".