emails: fix sending emails to invalid addresses.

Fix mailers to not attempt deliveries to invalid or nonexistent email
addresses. This usually happened when someone changed their email, and
we tried to send a confirmation email to a nonexistent address.
This commit is contained in:
evazion
2022-01-02 12:23:01 -06:00
parent 9ffc269e43
commit 32613f9bb1
8 changed files with 30 additions and 13 deletions

View File

@@ -141,7 +141,7 @@ class Dmail < ApplicationRecord
end
def send_email
if is_recipient? && !is_deleted? && to.receive_email_notifications? && to.can_receive_email?
if is_recipient? && !is_deleted? && to.receive_email_notifications?
UserMailer.dmail_notice(self).deliver_later
end
end

View File

@@ -361,11 +361,7 @@ class User < ApplicationRecord
end
module EmailMethods
def email_with_name
"#{name} <#{email_address.address}>"
end
def can_receive_email?(require_verification: true)
def can_receive_email?(require_verified_email: true)
email_address.present? && email_address.is_deliverable? && (email_address.is_verified? || !require_verification)
end