【发布时间】:2019-02-16 05:27:51
【问题描述】:
我已在 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 的用户问题。 非常感谢!
【问题讨论】:
-
您似乎没有正确设置发件人地址,因为它是从
from@example.com发送的。 GMail 不允许将不正确的地址作为反垃圾邮件的措施。 -
该配置是否设置在
config/environments/production.rb中?您的错误Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):似乎表明它尝试使用的配置不正确。 -
@RockwellRice 是的,所有配置都是我在
config/environments/production.rb中设置的,你能给我一些配置提示吗?非常感谢。 -
我一直对 gmail 和 Heroku 有疑问。即使我的配置是正确的,它仍然会被拒绝。我最终使用了 sendgrid,下面的评论推荐山魈。我不会推荐服务,但我会说我不得不放弃 gmail,因为即使配置正确,我也无法让它工作。
-
@RockwellRice 哦,谢谢你的帮助:D
标签: ruby-on-rails email heroku configuration gmail