Приложение Rails утверждает, что успешно отправляет электронную почту, но никогда не завершает задачу - PullRequest
0 голосов
/ 07 января 2019

Я работаю над приложением Rails, которое должно отправлять электронное письмо с подтверждением при регистрации нового пользователя.

Мой почтовик выглядит так:

def notify_email(volunteer)
    @volunteer= volunteer
    @admin = Volunteer.first
    mail(to: @admin.email, subject: 'New Application from ' + volunteer.first_name+ '!', body: 
'You have new applicants, please go check on your admin dashboard!

You can contact ' + @volunteer.first_name+ ' at: ' +@volunteer.email+ '.')

  end
end

В моем файле production.rb конфигурации электронной почты установлены следующим образом (имя пользователя / пароль gmail заменены на x):

config.action_mailer.perform_caching = false
 config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

  config.action_mailer.default_url_options = { :host => 'localhost:8080' }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "gmail.com",
    :user_name => 'xxxxxx', 
    :password => 'xxxxxxx',
    :authentication => "plain",
    :enable_starttls_auto => true
  } 

Мой контроллер имеет этот код:

def create
    @admin= Volunteer.first
    @volunteer = Volunteer.create(volunteer_params)
    @volunteer.save
    if @volunteer.save
            flash[:success] = "Successfully Registered!"        

            #email notifes admin of new registration
        NotifyMailer.notify_email(@volunteer).deliver_now

        redirect_to '/volunteer'
    end

И наконец, когда я тестирую приложение на локальном сервере, консоль выдает мне эту информацию (электронные письма снова отключены):

NotifyMailer#notify_email: processed outbound mail in 1.5ms
Sent mail to xxxx@xxxx.org (2004.5ms)
Date: Sun, 06 Jan 2019 16:04:49 -0600
From: xxxxxxx@gmail.com
To: xxxxx@xxxxx.org
Message-ID: <5c327b817c32e_3de83ca21e89202@LAPTOP-N2MQ7EL0.mail>
Subject: New Application from Rachel!
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Может кто-нибудь дать мне понимание того, что мне не хватает? Я проверил несколько форумов и тем, и похоже, что я следую за правильными шагами.

Заранее спасибо.

1 Ответ

0 голосов
/ 07 января 2019

Невозможно прокомментировать, но что произойдет, если вы позвоните

NotifyMailer.notify_email(@volunteer).deliver

вместо

NotifyMailer.notify_email(@volunteer).deliver_now

Я полагаю, что delivery_now ретранслирует фонового работника, такого как sidekiq, плюс попробуйте gem "letter_opener" , который откроет новую вкладку в вашем браузере для проверки вашей электронной почты.

...