无法使用Devise从Rails应用发送电子邮件

时间:2018-05-31 21:01:21

标签: ruby-on-rails gmail actionmailer

我有一个使用Devise gem进行注册的应用程序,我已经按照Action Mailer Configuration for Gmail上的Rails指南进行了操作,但是当我点击发送密码重置说明时,我没有收到任何电子邮件。这就是我所拥有的:

config/environments/development.rb

  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.default_url_options = { host: 'localhost:3000' }
  config.action_mailer.smtp_settings = {
    address:              "smtp.gmail.com",
    port:                 587,
    domain:               "example.com",
    authentication:       "plain",
    user_name:            ENV["TODO_USERNAME"],
    password:             ENV["TODO_PASSWORD"],
    enable_starttls_auto: true
  }

我已更新

config/initializers/devise.rb

config.mailer_sender = 'myemail@gmail.com'

我还尝试过authentication: "plain"authentication: :plain,我尝试了this tutorialthisthisthis,他们都提供了相同的配置,但它不起作用。我允许不太安全的应用here,但没有运气。我也试过删除

domain: "example.com"

完全改变

config.action_mailer.default_url_options = { host: 'localhost:3000' }

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

但这也没有帮助。 我也试过了:

ActionMailer::Base.smpt_settings = { ... }

相反,但没有运气。

我还尝试将此配置放到config/application.rb,重启服务器次数,但没有运气。

这是send = ing密码重置说明时的控制台日志:

Devise::Mailer#reset_password_instructions: processed outbound mail in 15.9ms
Sent mail to [hidden email] (269.2ms)
Date: Thu, 31 May 2018 22:40:03 +0200
From: [hidden email]
Reply-To: [hidden email]
To: [hidden email]
Message-ID: <5b105da3af6e6_164325fb584383ef@Home.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello [hidden email]!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=qeoAhLA2pevyy7wpbVEs">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 460ms (ActiveRecord: 9.9ms)

我已经尝试了一切。 有什么想法吗?

我正在使用Rails 5.2

0 个答案:

没有答案