第11章的最后一次练习是:
注册生产中的新帐户。你收到了电子邮件吗?
据我所知,它部分有效。当我通过Heroku注册部署的网站时,我收到一条错误消息
我们很抱歉,但出了点问题。
如果您是应用程序所有者,请检查日志以获取更多信息。
我从日志中看到已生成激活电子邮件,但它从未出现在我的电子邮件收件箱中。我不明白为什么。下面是从我用exampleemailaddress@gmail.com创建示例user2的点开始的Heroku日志。注意:这不是一个真实的电子邮件地址,但我之前尝试过2个真正的电子邮件地址我只是为了这篇文章而使用这个电子邮件和用户。
2017-11-24T05:33:14.342658+00:00 app[web.1]: <style>
2017-11-24T05:33:14.342659+00:00 app[web.1]: /* Email styles need to be inline */
2017-11-24T05:33:14.342660+00:00 app[web.1]: </style>
2017-11-24T05:33:14.342660+00:00 app[web.1]: </head>
2017-11-24T05:33:14.342661+00:00 app[web.1]:
2017-11-24T05:33:14.342662+00:00 app[web.1]: <body>
2017-11-24T05:33:14.342662+00:00 app[web.1]: <h1>Sample App</h1>
2017-11-24T05:33:14.342663+00:00 app[web.1]:
2017-11-24T05:33:14.342663+00:00 app[web.1]: <p>Hi owen,</p>
2017-11-24T05:33:14.342664+00:00 app[web.1]:
2017-11-24T05:33:14.342664+00:00 app[web.1]: <p>
2017-11-24T05:33:14.342665+00:00 app[web.1]: Welcome to the Sample App! Click on the link below to activate your account:
2017-11-24T05:33:14.342666+00:00 app[web.1]: </p>
2017-11-24T05:33:14.342666+00:00 app[web.1]:
2017-11-24T05:33:14.342668+00:00 app[web.1]: </body>
2017-11-24T05:33:14.342667+00:00 app[web.1]: <a href="https://still-beyond-10331.herokuapp.com/account_activations/B9E9MkbJBlUEbYTLvf_kZg/edit?email=owenjharrison%40gmail.com">Activate</a>
2017-11-24T05:33:14.342668+00:00 app[web.1]: </html>
2017-11-24T05:33:14.342669+00:00 app[web.1]:
2017-11-24T05:33:14.342669+00:00 app[web.1]: ----==_mimepart_5a17af1a3f1f2_b2843f306332--
2017-11-24T05:33:14.342670+00:00 app[web.1]:
2017-11-24T05:33:14.343060+00:00 app[web.1]: I, [2017-11-24T05:33:14.342982 #11] INFO -- : [a3094dfa-b0f6-45f5-862c-2c7f54404ad8] Completed 500 Internal Server Error in 1644ms (ActiveRecord: 1179.3ms)
2017-11-24T05:33:14.343765+00:00 app[web.1]: F, [2017-11-24T05:33:14.343705 #11] FATAL -- : [a3094dfa-b0f6-45f5-862c-2c7f54404ad8]
2017-11-24T05:33:14.343837+00:00 app[web.1]: F, [2017-11-24T05:33:14.343771 #11] FATAL -- : [a3094dfa-b0f6-45f5-862c-2c7f54404ad8] Net::SMTPAuthenticationError (535 Authentication failed: account disabled
2017-11-24T05:33:14.343839+00:00 app[web.1]: ):
2017-11-24T05:33:14.343895+00:00 app[web.1]: F, [2017-11-24T05:33:14.343839 #11] FATAL -- : [a3094dfa-b0f6-45f5-862c-2c7f54404ad8]
2017-11-24T05:33:14.346096+00:00 heroku[router]: at=info method=POST path="/users" host=still-beyond-10331.herokuapp.com request_id=a3094dfa-b0f6-45f5-862c-2c7f54404ad8 fwd="212.174.5.195" dyno=web.1 connect=1ms service=1666ms status=500 bytes=1891 protocol=https
2017-11-24T05:33:14.343959+00:00 app[web.1]: F, [2017-11-24T05:33:14.343909 #11] FATAL -- : [a3094dfa-b0f6-45f5-862c-2c7f54404ad8] app/models/user.rb:64:in `send_activation_email'
2017-11-24T05:33:14.343960+00:00 app[web.1]: [a3094dfa-b0f6-45f5-862c-2c7f54404ad8] app/controllers/users_controller.rb:25:in `create'
2017-11-24T05:36:54.633186+00:00 app[web.1]: I, [2017-11-24T05:36:54.633027 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Started POST "/users" for 212.174.5.195 at 2017-11-24 05:36:54 +0000
2017-11-24T05:36:54.639890+00:00 app[web.1]: I, [2017-11-24T05:36:54.639786 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Processing by UsersController#create as HTML
2017-11-24T05:36:54.639987+00:00 app[web.1]: I, [2017-11-24T05:36:54.639917 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Parameters: {"utf8"=>"✓", "authenticity_token"=>"CQjYjjt1aXFsx4katSkk6obNnD/51iGtETU9pizfRLgcAlZtSITgl15njTWOY89jO72Vp9DiKstg2CmSKHYeYg==", "user"=>{"name"=>"example user2", "email"=>"exaampleemailaddress@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Create my account"}
2017-11-24T05:36:54.787318+00:00 app[web.1]: D, [2017-11-24T05:36:54.787201 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] (1.2ms) BEGIN
2017-11-24T05:36:54.797518+00:00 app[web.1]: D, [2017-11-24T05:36:54.797427 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] User Exists (1.7ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER($1) LIMIT $2 [["email", "exaampleemailaddress@gmail.com"], ["LIMIT", 1]]
2017-11-24T05:36:54.872861+00:00 app[web.1]: D, [2017-11-24T05:36:54.872770 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] SQL (1.7ms) INSERT INTO "users" ("name", "email", "created_at", "updated_at", "password_digest", "activation_digest") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["name", "example user2"], ["email", "exaampleemailaddress@gmail.com"], ["created_at", "2017-11-24 05:36:54.797954"], ["updated_at", "2017-11-24 05:36:54.797954"], ["password_digest", "$2a$10$g6t4XvQPYYhVh3/tzNmd.ONZ9ldayN7KOfHW9cYLyOvEAqBtlLGZq"], ["activation_digest", "$2a$10$c.QMCwpe1zAJruyccsRQcecTF6co02uQ7J5/CLyX6UBCtCq2fnBpO"]]
2017-11-24T05:36:54.875122+00:00 app[web.1]: D, [2017-11-24T05:36:54.875062 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] (1.8ms) COMMIT
2017-11-24T05:36:54.881126+00:00 app[web.1]: I, [2017-11-24T05:36:54.881050 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Rendering user_mailer/account_activation.html.erb within layouts/mailer
2017-11-24T05:36:54.883484+00:00 app[web.1]: I, [2017-11-24T05:36:54.883420 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Rendered user_mailer/account_activation.html.erb within layouts/mailer (2.2ms)
2017-11-24T05:36:54.884432+00:00 app[web.1]: I, [2017-11-24T05:36:54.884375 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Rendering user_mailer/account_activation.text.erb within layouts/mailer
2017-11-24T05:36:54.884974+00:00 app[web.1]: I, [2017-11-24T05:36:54.884915 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Rendered user_mailer/account_activation.text.erb within layouts/mailer (0.4ms)
2017-11-24T05:36:55.036784+00:00 app[web.1]: D, [2017-11-24T05:36:55.036677 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] UserMailer#account_activation: processed outbound mail in 160.5ms
2017-11-24T05:36:55.180112+00:00 heroku[router]: at=info method=POST path="/users" host=still-beyond-10331.herokuapp.com request_id=d4329f23-2e16-485a-aec1-4e24c92b4d5c fwd="212.174.5.195" dyno=web.1 connect=1ms service=558ms status=500 bytes=1891 protocol=https
2017-11-24T05:36:55.176384+00:00 app[web.1]: I, [2017-11-24T05:36:55.176279 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Sent mail to exaampleemailaddress@gmail.com (139.4ms)
2017-11-24T05:36:55.176430+00:00 app[web.1]: D, [2017-11-24T05:36:55.176370 #6] DEBUG -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Date: Fri, 24 Nov 2017 05:36:55 +0000
2017-11-24T05:36:55.176431+00:00 app[web.1]: From: noreply@example.com
2017-11-24T05:36:55.176432+00:00 app[web.1]: To: exaampleemailaddress@gmail.com
2017-11-24T05:36:55.176433+00:00 app[web.1]: Message-ID: <5a17aff7a020_62843f6c634b6@7e0cfe46-bf9e-4ef5-bd82-f0d5ef32afd2.mail>
2017-11-24T05:36:55.176433+00:00 app[web.1]: Subject: Account activation
2017-11-24T05:36:55.176433+00:00 app[web.1]: Mime-Version: 1.0
2017-11-24T05:36:55.176434+00:00 app[web.1]: Content-Type: multipart/alternative;
2017-11-24T05:36:55.176435+00:00 app[web.1]: boundary="--==_mimepart_5a17aff78aa4_62843f6c633d1";
2017-11-24T05:36:55.176435+00:00 app[web.1]: charset=UTF-8
2017-11-24T05:36:55.176436+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2017-11-24T05:36:55.176436+00:00 app[web.1]:
2017-11-24T05:36:55.176437+00:00 app[web.1]:
2017-11-24T05:36:55.176437+00:00 app[web.1]: ----==_mimepart_5a17aff78aa4_62843f6c633d1
2017-11-24T05:36:55.176438+00:00 app[web.1]: Content-Type: text/plain;
2017-11-24T05:36:55.176438+00:00 app[web.1]: charset=UTF-8
2017-11-24T05:36:55.176438+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2017-11-24T05:36:55.176439+00:00 app[web.1]:
2017-11-24T05:36:55.176439+00:00 app[web.1]: Hi example user2,
2017-11-24T05:36:55.176440+00:00 app[web.1]:
2017-11-24T05:36:55.176440+00:00 app[web.1]: Welcome to the Sample App! Click on the link below to activate your account:
2017-11-24T05:36:55.176441+00:00 app[web.1]:
2017-11-24T05:36:55.176441+00:00 app[web.1]:
2017-11-24T05:36:55.176441+00:00 app[web.1]: https://still-beyond-10331.herokuapp.com/account_activations/wNgvDOzoPpFYMMD-D_lFFg/edit?email=exaampleemailaddress%40gmail.com
2017-11-24T05:36:55.176442+00:00 app[web.1]: ----==_mimepart_5a17aff78aa4_62843f6c633d1
2017-11-24T05:36:55.176442+00:00 app[web.1]: Content-Type: text/html;
2017-11-24T05:36:55.176443+00:00 app[web.1]: charset=UTF-8
2017-11-24T05:36:55.176443+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2017-11-24T05:36:55.176443+00:00 app[web.1]:
2017-11-24T05:36:55.176444+00:00 app[web.1]: <!DOCTYPE html>
2017-11-24T05:36:55.176444+00:00 app[web.1]: <html>
2017-11-24T05:36:55.176444+00:00 app[web.1]: <head>
2017-11-24T05:36:55.176445+00:00 app[web.1]: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2017-11-24T05:36:55.176445+00:00 app[web.1]: <style>
2017-11-24T05:36:55.176446+00:00 app[web.1]: /* Email styles need to be inline */
2017-11-24T05:36:55.176446+00:00 app[web.1]: </style>
2017-11-24T05:36:55.176446+00:00 app[web.1]: </head>
2017-11-24T05:36:55.176447+00:00 app[web.1]:
2017-11-24T05:36:55.176447+00:00 app[web.1]: <body>
2017-11-24T05:36:55.176447+00:00 app[web.1]: <h1>Sample App</h1>
2017-11-24T05:36:55.176448+00:00 app[web.1]:
2017-11-24T05:36:55.176448+00:00 app[web.1]: <p>Hi example user2,</p>
2017-11-24T05:36:55.176449+00:00 app[web.1]: Welcome to the Sample App! Click on the link below to activate your account:
2017-11-24T05:36:55.176449+00:00 app[web.1]: <p>
2017-11-24T05:36:55.176450+00:00 app[web.1]:
2017-11-24T05:36:55.176448+00:00 app[web.1]:
2017-11-24T05:36:55.176450+00:00 app[web.1]: </p>
2017-11-24T05:36:55.176451+00:00 app[web.1]: <a href="https://still-beyond-10331.herokuapp.com/account_activations/wNgvDOzoPpFYMMD-D_lFFg/edit?email=exaampleemailaddress%40gmail.com">Activate</a>
2017-11-24T05:36:55.176452+00:00 app[web.1]: </body>
2017-11-24T05:36:55.176452+00:00 app[web.1]: </html>
2017-11-24T05:36:55.176452+00:00 app[web.1]:
2017-11-24T05:36:55.176453+00:00 app[web.1]: ----==_mimepart_5a17aff78aa4_62843f6c633d1--
2017-11-24T05:36:55.176780+00:00 app[web.1]: I, [2017-11-24T05:36:55.176724 #6] INFO -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Completed 500 Internal Server Error in 537ms (ActiveRecord: 31.0ms)
2017-11-24T05:36:55.176453+00:00 app[web.1]:
2017-11-24T05:36:55.177316+00:00 app[web.1]: F, [2017-11-24T05:36:55.177264 #6] FATAL -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c]
2017-11-24T05:36:55.177363+00:00 app[web.1]: F, [2017-11-24T05:36:55.177320 #6] FATAL -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] Net::SMTPAuthenticationError (535 Authentication failed: account disabled
2017-11-24T05:36:55.177364+00:00 app[web.1]: ):
2017-11-24T05:36:55.177407+00:00 app[web.1]: F, [2017-11-24T05:36:55.177365 #6] FATAL -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c]
2017-11-24T05:36:55.177466+00:00 app[web.1]: F, [2017-11-24T05:36:55.177425 #6] FATAL -- : [d4329f23-2e16-485a-aec1-4e24c92b4d5c] app/models/user.rb:64:in `send_activation_email'
2017-11-24T05:36:55.177466+00:00 app[web.1]: [d4329f23-2e16-485a-aec1-4e24c92b4d5c] app/controllers/users_controller.rb:25:in `create'
编辑:下面添加的SMTP设置
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'https://still-beyond-10331.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
答案 0 :(得分:1)
将Smtp设置添加到config / environments / production.rb:
config.action_mailer.default_url_options = { host: 'still-beyond-10331.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "xxxxx@gmail.com",
:password => "xxxxxx",
:authentication => "plain",
:enable_starttls_auto => true
}