Как отправить письмо с помощью devise gem? - PullRequest
1 голос
/ 29 октября 2019

У меня следующая проблема, я хочу отправить электронное письмо для восстановления пароля пользователя с помощью ResetMailer и инициализатора устройства, но электронное письмо не отправляется. Это мой почтовик:

class ResetMailer < Devise::Mailer
  helper :application
  include Devise::Controllers::UrlHelpers
  default template_path: 'devise/mailer'
  default from: 'my_email@gmail.com'
  def delivery_options
    {
      user_name:      'MyUserName',
      password:       '##########',
      domain:         'sendgrid.com/',
      address:        'smtp.sendgrid.net',
      port:           '25',
      authentication: :plain,
      enable_starttls_auto: true
    }
  end
end

У меня есть это в инициализаторе моего устройства:

  # ==> Mailer Configuration
  # Configure the e-mail address which will be shown in Devise::Mailer,
  # note that it will be overwritten if you use your own mailer class
  # with default "from" parameter.
  # config.mailer_sender = 'desarrollocafeina@gmail.com'

  # Configure the class responsible to send e-mails.
  config.mailer = 'ResetMailer'

1 Ответ

0 голосов
/ 29 октября 2019

Вы можете выполнить следующие шаги:

Во-первых, у устройства есть функция, которая send_reset_password_instructions , вы можете использовать ее как: current_user.send_reset_password_instructions

Во-вторых, выследует переместить настройки почты в config/environments/development.rb

config.action_mailer.perform_deliveries = true

config.action_mailer.smtp_settings = {
  address: 'smtp.sendgrid.net',
  port: 25,
  domain: '*',
  user_name: '*',
  password: '*',
  enable_starttls_auto: true,
}

Наконец, вы можете изменить пароль для сброса почты в папке mailers как:

class ResetMailer < Devise::Mailer
  default from: 'my_email@gmail.com'

  def reset_password_instructions(record, token, opts = {})
    super
  end
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...