Рельсы Sendgrid Email не приходит - PullRequest
0 голосов
/ 17 марта 2020

У меня в почтовом приложении Rails 5.2 настроен почтовый модуль Sendgrid.

Почтовик выглядит так:

class NotificationMailer < ApplicationMailer

  default :from => 'man@manlyartofbbq.com'

  # send a signup email to the user, pass in the user object that   contains the user's email address
  def event_email(event)
    @event = event
    mail( :to => @event.user.email,
    :subject => 'Reminder: ' + @event.name + " is in 7 Days")
  end

end

И сейчас я звоню с rails c как это:

NotificationMailer.event_email(Event.find(1)).deliver

Хотя в конечном итоге я буду вызывать его с помощью этой задачи с граблями:

desc "Send reminder emails for events."

task :monthly => :environment do

  d = Date.today + 7.days

  Event.all.each do |e|
    if e.repeats == "Monthly"
      if e.first_date.day == d.day
        puts "Should send stuff for monthly."
        NotificationMailer.event_email(e).deliver
      end
    end
  end

end

Когда я звоню по электронной почте через rails c, все выглядит нормально :

[1] pry(main)> NotificationMailer.event_email(Event.find(1)).deliver
  Event Load (0.5ms)  SELECT  "events".* FROM "events" WHERE "events"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  User Load (0.6ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering notification_mailer/event_email.html.erb within layouts/mailer
  Rendered notification_mailer/event_email.html.erb within layouts/mailer (0.8ms)
NotificationMailer#event_email: processed outbound mail in 192.9ms
Sent mail to MYEMAILHERE@gmail.com (415.0ms)
Date: Mon, 16 Mar 2020 21:46:19 -0700
From: SENDER@EMAIL.com
To: MYEMAILHERE@gmail.com
Message-ID: <5e70561b4e70a_c8153fc2b2c32ee06f4@Lizs-MacBook-Pro.local.mail>
Subject: Reminder: Wedding Anniversary is in 7 Days
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

...insert correct email HTML here...

Но электронное письмо не приходит.

Я настроил sendgrid на Heroku и добавил правильные пароли и имена пользователей в мои application.yml

У меня есть это в my environment.rb:

ActionMailer::Base.smtp_settings = {
  :user_name => ENV["SENDGRID_USERNAME"],
  :password => ENV["SENDGRID_PASSWORD"],
  :domain => 'manlyartofbbq.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

Кто-нибудь может понять, почему электронное письмо никогда не приходит?

...